Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts hide only some series in legend

Is it possible to hide only some series in the legend.

I have a combo chart containing:

  • amount of A
  • amount of B
  • amount of C

all displayed as one stacked column.

and also:

  • amount/second of A
  • amount/second of B
  • amount/second of C

all displayed as separate lines within the same chart.

Now "amount of A" has the same color as "amount/second of A". This color should be displayed in the legend only once and labelled "A".

Is it possible to do that with Google Charts? If so, how?

like image 709
haferblues Avatar asked Sep 15 '14 13:09

haferblues


People also ask

How to hide a series from the legend in a chart?

How to hide a series from the legend? Highcharts.extend (options, Highcharts.merge (options, { series: [ { index: 2, showInLegend: "false" } ] })); results in a blank chart. In 'Custom code' section create a chart using options from 'Genereated options' section, add showInLegend property and set it to false in series with index 2.

How to populate the Google Chart without legend?

By default, legend is always shown in Google Chart and in order to hide legend, it needs to be disabled using Google Chart Options. Populating the Google Chart without Legend The very first thing is to load the Google Chart API packages and when once all the packages are loaded then the drawChart method is invoked.

How to set showinlegend property to false in Highcharts?

Highcharts.extend (options, Highcharts.merge (options, { series: [ { index: 2, showInLegend: "false" } ] })); results in a blank chart. In 'Custom code' section create a chart using options from 'Genereated options' section, add showInLegend property and set it to false in series with index 2.

How do I hide a legend entry?

You can manually hide a legend entry by selecting it (select the legend first, then the entry, using two single clicks) and pressing Delete.


1 Answers

You can remove specific entries from the legend by setting the chart's series.<series index>.visibleInLegend options to false for the series you want to hide from the legend. As an example, if the amount/second series are the 4th, 5th, and 6th data series in your data set, you could create a series option like this to hide them:

series: {
    3: {
        visibleInLegend: false
    },
    4: {
        visibleInLegend: false
    },
    5: {
        visibleInLegend: false
    }
}

The series index is counting data series only, not DataTable columns, so ignore your domain column and any special role columns you are using when determining the series index.

like image 175
asgallant Avatar answered Oct 12 '22 12:10

asgallant