所以即时使用chart.js http://www.chartjs.org/docs/ 我无法改变底部文字的颜色
例如: " 1""二月""三月"" 4月""五月"" 6月& #34;" 7月" 以及左侧的数字
我尝试了所有这些选项: scaleFontColor:" #FFFFFF" pointLabelFontColor:" #FFFFFF"
我的完整代码:
<script>
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var lineChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
label: "My Second dataset",
fillColor : "rgba(255, 89, 114, 0.6)",
strokeColor : "rgba(51, 51, 51, 1)",
pointColor : "rgba(255, 89, 114, 1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(151,187,205,1)",
maintainAspectRatio: false,
scaleFontColor: "#FFFFFF",
pointLabelFontColor : "#FFFFFF",
pointLabelFontSize : 30,
data : [1,2,10,7,3,1]
}
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
});
}
</script>
答案 0 :(得分:13)
工作代码就是这样:
Chart.defaults.global.defaultFontColor = "#fff";
玩得开心:)
答案 1 :(得分:6)
scaleFontColor
用于更改标签的颜色。
不应将其添加到数据集中,而应将其作为参数添加到函数中,如下所示:
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true, scaleFontColor: "#FFFFFF" }
});
答案 2 :(得分:1)
在 Chart.js v3 中可以通过以下方式实现:
Chart.defaults.color = "#ff0000";
答案 3 :(得分:0)
对于 chart.js 3.x 迁移,x 和 y 轴上的文本标签设置为:
设置以下选项:
scales: {
x: {
ticks: {
color: "red"
}
},
y: {
ticks: {
color: "green"
}
}
}
如果你想改变网格线的颜色,找到类似的解决方案,在 x / y 值写入内部
grid: {
color: "white"
}
答案 4 :(得分:-1)
我和凯南一起找到了这个问题
<script>
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var lineChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
label: "My Second dataset",
fillColor : "rgba(255, 89, 114, 0.6)",
strokeColor : "rgba(51, 51, 51, 1)",
pointColor : "rgba(255, 89, 114, 1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(151,187,205,1)",
maintainAspectRatio: false,
data : [1,2,10,7,3,1]
}
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true, scaleFontColor: "#FFFFFF" }
)};
</script>
它不是正常的数据类型,我必须正确调整括号!
非常感谢,现在看起来很棒。