chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.9k stars 11.88k forks source link

Set label of piechart/donut chart using parsing #11772

Open anuj9196 opened 1 month ago

anuj9196 commented 1 month ago

Feature Proposal

The line chart supports the parsing of data as

dataset = [
{
    data: [{
      label: 'Sale',
      value: 15
    }, {
      label: 'Purchase',
      value: 20
    }]]
}

...
options = {
  parsing: {
    xAxisKey: 'label',
    yAxisKey: 'value'
  }
}

But in the case of a pie chart and doughnut chart, there is only one parsing key

options = {
  parsing: {
    key: 'value'
  }
}

But how can I set the label for in this case?

As a workaround, I still need to do data processing to extra labels and set labels explicitly.

Possible Implementation

On option to set label to the data of pie chart as well.

e.g.,

options = {
  parsing: {
    key: 'value',
    label: 'label'
  }
}