score:16

Accepted answer

just went through the code on their sample. it appears that an object in the data set array should have the following structure

{
            data: [
                <a number>,
                <a number>,
                ...
            ],
            backgroundcolor: [
                <a colour>,
                <a colour>,
                ...
            ],
            label: 'unique label for this data set
}

i have created the below snippet for you.

var config = {
  type: 'doughnut',
  data: {
    datasets: [
     /* outer doughnut data starts*/
    {
      data: [
        10,
        20,
        30
      ],
      backgroundcolor: [
        "rgb(255, 0, 0)", // red
        "rgb(0, 255, 0)", // green
        "rgb(0, 0, 255)", //blue
      ],
      label: 'doughnut 1'
    },
    /* outer doughnut data ends*/
    /* inner doughnut data starts*/
    {
      data: [
        45,
        25,
        11
      ],
      backgroundcolor: [
        "rgb(255, 0, 0)", // red
        "rgb(0, 255, 0)", // green
        "rgb(0, 0, 255)", //blue
      ],
      label: 'doughnut 2'
    }
    /* inner doughnut data ends*/
    ],
    labels: [
      "info 1",
      "info 2",
      "info 3"
    ]
  },
  options: {
    responsive: true,
    legend: {
      position: 'top',
    },
    title: {
      display: true,
      text: 'chart.js doughnut chart'
    },
    animation: {
      animatescale: true,
      animaterotate: true
    },
    tooltips: {
      callbacks: {
        label: function(item, data) {
        console.log(data.labels, item);
            return data.datasets[item.datasetindex].label+ ": "+ data.labels[item.index]+ ": "+ data.datasets[item.datasetindex].data[item.index];
        }
    }
}
  }
};
window.onload = function() {
  var ctx = document.getelementbyid("mychart")
    .getcontext("2d");
  window.mydoughnut = new chart(ctx, config);
};
<html>

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.6.0/chart.bundle.js"></script>
</head>

<body>
  <canvas id="mychart"></canvas>
</body>

</html>


Related Query

More Query from same tag