2

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);
}); 
Merrily
  • 1,686
  • 10
  • 14

1 Answers1

2

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>
nardecky
  • 2,623
  • 8
  • 18
  • Thanks , is there a way to make the hover feature appear i.e. when I hover over an item in the legend the respective series must be higlighted.(this feature is a default feature but gets disabled when when we give 'action-toggle' as either 'disabled' or 'none' – user5210703 Nov 14 '16 at 10:33
  • You can view [legend guide](https://www.zingchart.com/docs/tutorials/chart-elements/interactive-chart-legend/) and [legend docs](https://www.zingchart.com/docs/api/json-configuration/graphset/legend/). Attribute `highlightPlot:true` will do the trick. – nardecky Nov 14 '16 at 19:46