Home Forums Chart Support Legend

Legend

Viewing 2 posts - 1 through 2 (of 2 total)
  • #36768

    Hello, is it possible to display a legend for a group of series? I have series divided into series by color, in each group the series have the same color and I need to display the legend only by groups. but all series should be display.

    #36800

    @mailtokosgmail-com,

    To display the legend for a group of data series, you can use the showInLegend property in any one of the data series in a group. You can also pass a custom property group to each data series and use this property to hide/unhide the data series using itemclick property of legend as shown in the code-snippet below,

    function onLegendClick(e) {
      var groupSelected = e.dataSeries.group;
      for(var i = 0; i < e.chart.data.length; i++) {
        if(e.chart.options.data[i].group === groupSelected) {
          if (typeof (e.chart.options.data[i].visible) === "undefined" || e.chart.options.data[i].visible) {
            e.chart.options.data[i].visible = false;
          } else {
            e.chart.options.data[i].visible = true;
          }
        }
      }
    }

    Kindly take a look at this JSFiddle for an example with complete code.

    legends for a group of dataSeries


    Adithya Menon
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.