Skip to content

The example for overriding legend onClick is outdated #12144

@MyrionSC

Description

@MyrionSC

Documentation Is:

  • Missing or needed?
  • Confusing
  • Not sure?

Please Explain in Detail...

Concerning https://www.chartjs.org/docs/latest/configuration/legend.html

The example for overriding legend onClick is outdated. The code throws error Uncaught TypeError: Cannot read properties of null (reading '_resolveAnimations'

it is currently:

function(e, legendItem, legend) {
    const index = legendItem.datasetIndex;
    const ci = legend.chart;
    if (ci.isDatasetVisible(index)) {
        ci.hide(index);
        legendItem.hidden = true;
    } else {
        ci.show(index);
        legendItem.hidden = false;
    }
}

Your Proposal for Changes

It should be

legend.chart.toggleDataVisibility(legendItem.index);
legend.chart.update();

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions