score:6
Accepted answer
It is possible to control the color of each slice in a pie/doughnut chart using the backgroundColor
dataset property.
It looks like you were attempting to do this in your question, but here is a full working example so that you can leverage it for your needs.
var config = {
type: 'doughnut',
data: {
datasets: [{
data: [300, 50, 100, 40, 10],
backgroundColor: [
window.chartColors.red,
window.chartColors.orange,
window.chartColors.yellow,
window.chartColors.green,
window.chartColors.blue,
],
}],
labels: [
"Red",
"Orange",
"Yellow",
"Green",
"Blue"
]
},
options: {
responsive: true,
legend: {
display: true,
labels: {
padding: 20
},
},
tooltips: {
enabled: false,
}
}
};
Here is a working Codepen example.
Source: stackoverflow.com
Related Query
- Configure Pie Chart Colors Using Chart.js and PHP
- Grouped Bar Chart from mySQL database using ChartJS and PHP
- create Chart using Chartjs and PHP
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Unable to see pie chart in template using django and chart js
- Pie chart using chart.js and asp.net web Service (asmx)
- Pie chart not working using angular and ng2-charts
- pie chart in php with mysql data using chart.js
- Chartjs random colors for each part of pie chart with data dynamically from database
- chartjs datalabels change font and color of text displaying inside pie chart
- How to save Chart JS charts as image without black background using blobs and filesaver?
- Chart.js ng2-charts colors in pie chart not showing
- Chart.js - Getting data from database using mysql and php
- Chart.js: width and height of a pie chart not respected
- How to create single value Doughnut or Pie chart using Chart.js?
- Chart,js Pie Chart can the gap between a pie chart and the legend be adjusted
- How do you set pie chart colors in angular-chart.js
- How to Increase the label font size and decrease the size of my pie using chart.js?
- How to create a gantt chart using Chart.js and populate dates?
- Create Chart using Reactjs Chartjs and axios
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- Using chart js options with react-chartjs-2 and typescript
- Trying to load a chart with chart.js, through ajax and php
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- Dynamic line chart with chart.js and PHP
- Chart only prints out first value using jquery ajax php
- how to add percentage value to legend field in pie chart using chart.js
- How to export a chart in Excel and PDF format using Chart.js
- How to show slice value inside of slice in pie chart using chart.js
- Text inside Doughnut chart using Chart.js and Angular2, Ionic2
More Query from same tag
- Chart JS: Set Spacing Between Ticks on Y-Axis
- Format Y axis of Chart.JS as Time
- make chartjs legend labels tabbable
- How to add horizontal scroll to a bar graph in chartjs?
- How to pass data for stacked chart in vue-chartkick
- What is the correct format for time data in chartjs?
- Destroy chart.js bar graph to redraw other graph
- Method inside Activate in Aurelia
- How to push an array into an Object which is inside of another array?
- Legend option destroys pie chart in Chart.js
- How to make animated bar graph with canvas?
- Can i set dynamic step size on stepped line chart in chart.js?
- chartkick chart.js change colour of axis and colour of axis title
- angular-chart.js - define set Y axis width
- Unable to ES6 import ChartJS plugin into Aurelia
- Chart.js scatter plot fill portions of chart based on value
- Not able to see values on bar chart
- Angular-chart / line chart with multiple horizontal lines (margins)
- Vertical Gird Line Issue with Chart.js
- Chart.js and react-chartjs-2 property translate is missing type
- ng2-charts: How to set Title of chart dynamically in typescript
- Chart.js not to be begin in Y-Axis
- Adding caret/arrow to a Chart.js custom html tooltip
- ChartJS bubble plot categorical y-labels with numbers in string plot issue
- Html5 web page with chartjs: loading an external json file and create a line chart
- Split JSON into two arrays gives undefined keys-values
- Dashed line for missing data in Chart.JS (spanGaps style)
- Angular 4: Different color for bar in bar chart dynamically using ChartJS
- Angular 8 & ChartJs change color in pie chart
- ChartJS Tooltip Customization