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.

Possibility for adding multiple label-arrays for multiple dataset doughnut diagrams

See original GitHub issue

When creating a doughnut diagram with multiple rings there seems to be no option for adding different arrays of labels. One array for each dataset. For example in this chart a option, so every item has it’s color name as label (tooltip):

  var ctx = $("#myChart");
  var myChart = new Chart(ctx, {
  type: 'doughnut',
      data: {
          labels: ["Green", "Yellow", "Red", "Purple", "Blue"],
          datasets: [
            {
              data: [1,2,3,4,5],
              backgroundColor: [
                  'green',
                  'yellow',
                  'red',
                  'purple',
                  'blue',
              ],
            },
            {
              data: [6,7,8],
              backgroundColor: [
                  'black',
                  'grey',
                  'lightgrey'
              ],
            },
          ]
      },
  options: {
    responsive: true,
    legend: {
      display: false,
    }
  }
  });

https://jsfiddle.net/tgsdje3r/

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

23reactions
etimbergcommented, Feb 24, 2017

Adding some extra data to the datasets and then changing the tooltip label callback works: https://jsfiddle.net/moe2ggrd/1/

21reactions
mnpennercommented, Sep 30, 2017

Hope you don’t mind, I’m just going to copy the code out of that fiddle and paste it here in case it disappears since it’s really useful!

var ctx = $("#myChart");
var myChart = new Chart(ctx, {
    type: 'doughnut',
    data: {
        datasets: [{
            data: [1, 2, 3, 4, 5],
            backgroundColor: [
                'green',
                'yellow',
                'red',
                'purple',
                'blue',
            ],
            labels: [
                'green',
                'yellow',
                'red',
                'purple',
                'blue',
            ]
        }, {
            data: [6, 7, 8],
            backgroundColor: [
                'black',
                'grey',
                'lightgrey'
            ],
            labels: [
                'black',
                'grey',
                'lightgrey'
            ],
        },]
    },
    options: {
        responsive: true,
        legend: {
            display: false,
        },
        tooltips: {
            callbacks: {
                label: function(tooltipItem, data) {
                    var dataset = data.datasets[tooltipItem.datasetIndex];
                    var index = tooltipItem.index;
                    return dataset.labels[index] + ': ' + dataset.data[index];
                }
            }
        }
    }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add Multiple Text Labels Stacked in Doughnut Chart in ...
How to Add Multiple Text Labels Stacked in Doughnut Chart in Chart JSIn this video we will explore how to add multiple text...
Read more >
How to create a Multiple Donuts chart - Datawrapper Academy
A multiple donuts chart is useful when you want to show proportional parts of multiple wholes and want to give the reader an...
Read more >
How to add a second set of labels to a Chart.js doughnut chart?
Add a labels array to both of the datasets var config = { type: 'doughnut', data: { datasets: [ { data: [124,231,152,613,523], ...
Read more >
Donut Charts - Salesforce Help
Use a donut chart when you have multiple groupings and want to show not only the proportion of a single value for each...
Read more >
Doughnut Chart in Excel - GeeksforGeeks
Inserting Charts in Excel: · We want to represent multiple datasets on a single chart. · Each dataset has a maximum of 6-7...
Read more >

github_iconTop Related Medium Post

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