Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on Legend Configuration is outdated - please update #11915

Closed
1 of 3 tasks
coreymunn3 opened this issue Oct 1, 2024 · 2 comments
Closed
1 of 3 tasks

Documentation on Legend Configuration is outdated - please update #11915

coreymunn3 opened this issue Oct 1, 2024 · 2 comments

Comments

@coreymunn3
Copy link

Documentation Is:

  • Missing or needed?
  • Confusing
  • Not sure?

Please Explain in Detail...

Currently, at the configuration > legend section, if you scroll down to custom onClick actions, it says the default behavior is this

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;
    }
}

However this is not correct. When I copied and pasted that code into my options.plugins.legend.onClick function, I got several errors summarized perfectly in this stackoverflow post.

The post also explains the fix and the purpose of this issue, which is to update the chartjs Docs to say, the current default behavior is actually

(e, legendItem, legend) => {
                                legend.chart.toggleDataVisibility(
                                  legendItem.index
                                );
                                legend.chart.update();
                              }

Your Proposal for Changes

Change the documentation to be correct as stated above.

Example

https://www.chartjs.org/docs/latest/configuration/legend.html#custom-on-click-actions

@LeeLenaleee
Copy link
Collaborator

Do you have a reproducible sample of your error, since this implementation in the docs is not outdated. This is the exact implementation the legend plugin currently uses.

https://github.com/chartjs/Chart.js/blob/ea88dba68d41d4974c1fff5ce1c60f5d68279c13/src/plugins/plugin.legend.js#L645C5-L655C7

image

@LeeLenaleee
Copy link
Collaborator

Closing as per my above comment, if you still have the issue feel free to re open the issue

@LeeLenaleee LeeLenaleee closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants