The default functionality in ZingChart for legends while clicking the item is to hide all the respective bar series that is related to that item value in legend.
I am performing a drilldown operation, which is fetching data for graph from server while clicking the legend item and then plotting a new chart with it. Now I dont want those bars to disappear while clicking the legend item and at the sametime want to perform onclick event when selecting the legend.
When I add : "toggle-action":"disabled"
inside the legends , the disappearence of the bars does not happen so does the onclick event.
Following is the legend item click function that I have written:
zingchart.bind("hbarChart", "legend_item_click", function (p) {
var data= p.xdata.band[0];
getData(data);
});
I think you just need to change toggleAction:
disabled
to none
.
var myConfig = {
type: 'bar',
legend: {
toggleAction:'none'
},
series: [
{
values: [35,42,67,89]
},
{
values: [25,34,67,85]
}
]
};
function legendClickHandler(){
console.log('test worked!');
}
zingchart.bind('myChart', 'legend_item_click', legendClickHandler );
zingchart.bind('myChart', 'legend_marker_click', legendClickHandler );
zingchart.render({
id: 'myChart',
data: myConfig,
height: '100%',
width: '100%'
});
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
#myChart {
height:100%;
width:100%;
min-height:150px;
}
<!DOCTYPE html>
<html>
<head>
<!--Assets will be injected here on compile. Use the assets button above-->
<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
</head>
<body>
<div id="myChart"></div>
</body>
</html>