【发布时间】:2019-06-28 23:16:22
【问题描述】:
我正在使用 Chart.js (http://www.chartjs.org/docs/) 绘制图表。 我的类型 Chart 是 Bar。
X 轴的标签有 4 行。 I 更改 X 轴值的颜色。值的颜色是一种颜色。 但我希望每种颜色有一条线,并且颜色与条形颜色相同。
var barChartData = {
labels: [["Injection", 10, 20], // here I want to change the color
["Electronics", 5, 15],
["TOTAL", 15, 35]
],
datasets: [{
label: "2018",
backgroundColor: window.chartColors.orange,
yAxisID: 'A',
data: [10, 5, 15]
}, {
label: "2017",
backgroundColor: window.chartColors.green,
yAxisID: 'A',
data: [20, 15, 35]
}]
};
var canvas = document.getElementById('canvas').getContext('2d');
new Chart(canvas, {
type: 'bar',
data: barChartData,
options: {
scales: {
yAxes: [{
id: 'A',
type: 'linear',
position: 'left',
}, {
id: 'B',
type: 'linear',
position: 'right',
ticks: {
max: 100,
min: 0
}
}],
xAxes: [{
ticks: {
fontColor: "#222", // This here that I changed.
},
}]
}
}
})
我想更改标签的颜色,10、5、15 为橙色,20、15、35 为绿色,Injection、Electronics、TOTAL 为黑色
我可以这样做吗?怎么样?
【问题讨论】:
标签: javascript jquery chart.js