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>
Source: stackoverflow.com
Related Query
- How to use two datasets in chart.js doughnut chart?
- How do I display two datasets on a single chart with chartjs
- Angular chart js how to use formatter with Doughnut chart
- How to add space between datasets in ng2 doughnut chart
- How to add text inside the doughnut chart using Chart.js?
- How to use two Y axes in Chart.js v2?
- How can I make two of my lines in Chart JS thicker
- How to add text in centre of the doughnut chart using Chart.js?
- How to use PrimeNg Chart of Width and Height?
- How to display the labels in doughnut chart using ng2 charts?
- How to create single value Doughnut or Pie chart using Chart.js?
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- How to use radial CanvasGradients with Chart.js's doughnut chart?
- Chart.js plotting two json datasets on a line chart
- How to add title inside doughnut chart in Angular Chart?
- How to map json array to two different array for chart
- How do I use my chart.js line chart with handlebars?
- ChartJS : How to display two "y axis" scales on a chart
- How to use segment property to color line / border color based on value in chart js?
- How to use JSON data in creating a chart with chartjs?
- How to use same data / labels on two y axes in Chart.js
- How to use set the color for each bar in a bar chart using chartjs?
- angular-chart.js doughnut chart : How do I change width of the arc of a doughnut?
- ChartJs - Round borders on a doughnut chart with multiple datasets
- How to fit Doughnut Chart JS into Bootstrap column?
- Chart.js - Connect two datasets in a line chart at same y value
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- How to rotate the Label text in doughnut chart slice vertically in chart.js canvas, Angular 12?
- how can i use chart.js to create a chart that has one time series line and one linear line on it at the same time?
More Query from same tag
- Chartjs - Two Y-axis scale problems
- Bar chart from Vue-chartjs doesn't render
- Chart.js showing x-axis ticks even though set to false
- Chart Data Not Updating for Both Graphs?
- How can I achieve displaying data points on chart but Dotted? Chart.js V3.7.0
- chart js how do I only show just the low/high dots on line chart?
- Remove only y-axis line from chat drawn using chart.js 1.0.2
- Background-color for area below line chart in chartJs?
- Chart Js flickering or switching as i move mouse on canvas
- html-pdf: How to ensure image doesn't span a page break
- Non numeric for x-axis in scatter chart in CHART.js
- Chart.js dynamic bar width
- Django - update dictionary with missing date values, set to 0
- Chart.js line graph data not displaying
- How to update a react-chartjs-2 plot using useState()
- Ng2-charts Time xAxes : unwanted high zoom on click
- chart.js 2.7.1 | Updating charts with variables
- Passing the same props while rendering different elements conditionally in React.js
- How to display small numbers in chart js tooltip?
- Chart.js How to actualize canvas due to new x-axis range typed by user
- Visual Studio 2013 IIS web site - problems with JS files
- Make non-zero value as mid-point for horizontal bar chart?
- Add all data in the tooltip of Chart JS
- Chart.js - Add gradient to bar chart
- Accessing data in an associative array in CodeIgniter 3
- How do I add JSON Data into ChartJS
- PrimeNG pie chart randomly displays, and displays on change of resolution
- How to pass a chart.js chart data object in json from a controller in asp.net mvc
- Chart section is empty
- I can't change the legend position in Laravel Charts & ChartJS