【发布时间】:2018-01-10 19:14:28
【问题描述】:
我尝试将 Y 轴和 X 轴的图表标签颜色更改为白色。我尝试在 stackoverflow 上使用其他线程的 fontColour 添加代码,但无法正常工作。
这是我的代码:
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var lineChartData = {
labels : ['January','February','March','April','May','June','July'],
datasets : [
{
label: 'My First dataset',
fontColor : '#fff' ,
backgroundColor : 'rgba(220,220,220,0.2)',
borderColor : 'rgba(220,220,220,1)',
pointBackgroundColor : 'rgba(220,220,220,1)',
pointBorderColor : '#fff',
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}
]
}
var options = {
maintainAspectRatio: false,
legend: {
fontColor: "white",
},
scales: {
xAxes: [{
ticks: {
fontColor: "white",
}
}],
yAxes: [{
ticks: {
fontColor: "white",
beginAtZero: true,
maxTicksLimit: 5,
stepSize: Math.ceil(250 / 5),
max: 250
}
}]
}
};
var ctx = document.getElementById('canvas-1');
var chart = new Chart(ctx, {
type: 'line',
data: lineChartData,
options: {
responsive: true
}
});
【问题讨论】:
-
您的
options块看起来不错,应该更改标签颜色,但在设置图表时实际上并没有包含它 -
谢谢! :D 工作
标签: javascript chart.js