Skip to content

Show/hide All nested data in ChartJS Pie chart when outer is shown/hidden #10074

Answered by Udemology
LukePrior asked this question in Q&A
Discussion options

You must be logged in to vote

Hi LukePrior,

Based on LeeLenalee I tried to create something and mostlikely you want to convert the legend into a style similar to bar chart where the dataset would show/hide if clicked on.

In case you need to understand what has been done watch this here: https://youtu.be/_M8ijxCE7mY

The code below shows you the config block. Just add it in your code and it will work nicely. Hope this helps.

    // config 
    const config = {
      type: 'doughnut',
      data,
      options: {
        cutout: '80%',
        plugins: {
          legend: {
            onClick: (evt, legendItem, legend) => {
              const datasets = legend.legendItems.map((dataset, index) => {
                retur…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by LukePrior
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants