Skip to content

[Bug]: Labels stay visible after closing pie-part via HTML legend #1158

Not planned

Description

@rmaxx

Would you like to work on a fix?

  • Check this if you would like to implement a PR, we are more than happy to help you go through the process.

Current and expected behavior

Not sure if its a bug, but i couldnt find a way to fix this.

Example: https://codepen.io/k3no/pen/WGmVBM?editors=0010 ( not my code, but i saw the same issue here)

When using a custom legend (html) and closing elements in pie charts, the labels on the chart stay visible.
I'm having the same issue with my react-chart-js code. I cant seem to find a way to address the labels on the chart to vanish when the arc itselfs gets hidden.

My code for the legendclick:
`
const handleLegendClick = (e,datasetIndex,ref) => {

const target = e.currentTarget;

target.classList.toggle('hidden');
const chart = ref;
let currentItem = '';
const chartdata = chart.getDatasetMeta(0);
if(chartdata.type === 'pie' || chartdata.type === "doughnut"){
  currentItem = chartdata.data[datasetIndex];
  currentItem.hidden ? currentItem.hidden=false: currentItem.hidden=true;
}
else{
  chart.getDatasetMeta(datasetIndex).hidden = chart.getDatasetMeta(datasetIndex).hidden === null ? true : !chart.getDatasetMeta(datasetIndex).hidden;
}
chart.update(); 

};

`

This opens an closes the pie element, but the label stays visible when the piece of the pie is closed.
Standard legend also hides the label after closing it.

Reproduction

https://codepen.io/k3no/pen/WGmVBM?editors=0010

chart.js version

v0.3.24

react-chartjs-2 version

v5.2.0

Possible solution

make labels on piechart changable through the chart object, of add a function to do this.

Activity

  1. changed the title [-][Bug]: [/-] [+][Bug]: Labels stay visible after closing pie-part via HMTL legend[/+] on Mar 16, 2023
  2. changed the title [-][Bug]: Labels stay visible after closing pie-part via HMTL legend[/-] [+][Bug]: Labels stay visible after closing pie-part via HTML legend[/+] on Mar 16, 2023
  3. dangreen commented on Nov 30, 2026

    @dangreen
    Collaborator

    Closing: this is about how Chart.js itself behaves or is configured, while react-chartjs-2 passes data, options and plugins to Chart.js as they are. The Chart.js docs cover it: https://www.chartjs.org/docs/latest/ If it turns out to be a bug, please report it to Chart.js: https://github.com/chartjs/Chart.js/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions