question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to configure visibility status of a dataset, to retain visibility state of datasets hidden by clicking Legend label

See original GitHub issue

Feature 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:closed
  • Created 3 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
LeeLenaleeecommented, Feb 18, 2021

@k1r0s guess you are using v2 of the lib, in that case you will have to do chart.getDatasetMeta(datasetIndex).hidden = true/false and then chart.update()

1reaction
k1r0scommented, Feb 18, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chart.js change legend toggle behaviour - Stack Overflow
To reverse how legend label clicking behaves, you can use the legend ... to toggle visibility based upon the current state ci.data.datasets.
Read more >
Create reports with the custom report builder
Enter the dashboard's name, and select its visibility. In the bottom right, click Save. You can also export a report to take your...
Read more >
Preserving UI State, like Zoom, in dcc.Graph with uirevision ...
I'd to share with you a really cool dash-core-components prerelease: the ability to preserve UI state in the dcc.Graph between callbacks.
Read more >
Using row-level security (RLS) with user-based rules to restrict ...
You can do this before or after you have shared the dataset. When you share a dataset with RLS with dataset owners, they...
Read more >
How to Toggle Graphs Visibility By Clicking Legend Label in ...
In this #Matplotlib tutorial, I will go over the steps how to use Matplotlib legend to toggle charts' visibility in Python.01:57 Create x ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found