Skip to content Skip to sidebar Skip to footer

Tell If An Line Is Hidden

I have a chart that has multiple lines, each of which is plotted on it's own y-axis. I have been trying to set it up so that when a line is hidden via the legend the axis it is on

Solution 1:

Since it works for you, I'm setting it as an answer

The _meta property in your datasets is very useful, especially when searching for specific properties such as hidden. However it is quite difficult to handle it when there are several charts on the same page.

When doing the following :

var isHiddenMeta = scatterChart.data.datasets[j]._meta[0].hidden;

The 0 index is actually the first chart called in your code (index 1 is the second, etc..) So you'll get the information of the first chart, and not the one you just clicked on.


To fix this, you need to use the Object.keys() method coupled with your dataset information, as follows :

var isHiddenMeta = scatterChart.data.datasets[j]._meta[Object.keys(scatterChart.data.datasets[j]._meta)[0]].hidden;

This will get you the hidden property of the dataset of the real chart.

Post a Comment for "Tell If An Line Is Hidden"