使用Chart.js和PHP配置饼图颜色
我一直在尝试为不同的区域启用不同的颜色,但我找不到为不同的对象使用不同颜色的方法 我正在从数据库中提取数据,然后按照如下方式处理它 如果您能就如何更改不同物品的颜色提出意见,我将不胜感激使用Chart.js和PHP配置饼图颜色,chart.js,pie-chart,Chart.js,Pie Chart,我一直在尝试为不同的区域启用不同的颜色,但我找不到为不同的对象使用不同颜色的方法 我正在从数据库中提取数据,然后按照如下方式处理它 如果您能就如何更改不同物品的颜色提出意见,我将不胜感激 //looping through the data for(var i in data) { CarPrices.push(data[i].name); score.push(data[i].price); } //Working with data fetched from databas
//looping through the data
for(var i in data) {
CarPrices.push(data[i].name);
score.push(data[i].price);
}
//Working with data fetched from database
var chartdata = {
labels: player,
datasets : [
{
//Trying to change background color for each element
label: 'Car Prices',
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
//Trying to change background color for each element**
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
}
]
};
可以使用
backgroundColor
dataset属性控制饼图/甜甜圈图中每个切片的颜色
看起来您在您的问题中试图这样做,但这里有一个完整的工作示例,以便您可以利用它满足您的需要
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,
}
}
};
这是一个工作表。是否也可以提及图例值?