Ability to configure visibility status of a dataset, to retain visibility state of datasets hidden by clicking Legend label
See original GitHub issueFeature Proposal
I’m using Chart.js (v3.x.x) with React, using chartjs-react wrapper.
I would like to know if there is a way to configure a dataset to be hidden
. The use case is described below, wherein, once a dataset is hidden by clicking on its legend label, the visibility of this dataset can’t be retained when new datasets are added to the graph.
Feature Use Case
When a dataset in a line chart gets hidden by clicking on its label in the legend, and then if a new dataset is added, the previously hidden dataset gets enabled/shown again as the component re-renders and I could not find a way to set the “visibility / hidden” status of a dataset in the docs.
Possible Implementation
Using the generateLabels
and onClick
callbacks on Legend plugin, one can keep track of which fields are in hidden state.
By exposing a hidden property in the dataset’s config, consumers can configure which datasets they would like to be in hidden state.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (12 by maintainers)
Top GitHub Comments
@k1r0s guess you are using v2 of the lib, in that case you will have to do
chart.getDatasetMeta(datasetIndex).hidden = true/false
and thenchart.update()
Hello, just googling around and I came here looking for a way to programatically hide some information within the chart after has loaded.
this instruction works
chart.legend.legendItems[datasetIndex].hidden
but either of this two do not:
chart.hide(datasetIndex), chart.show(datasetIndex)
there are no hide or show functions defined on the prototype. (I assume ‘chart’ happens to be the instance returned from new Chart( … ))
Thanks in advance