gpt4 book ai didi

javascript - Chart.js 标签颜色

转载 作者:IT王子 更新时间:2023-10-29 03:16:34 29 4
gpt4 key购买 nike

我正在使用 chart.js 创建条形图,但似乎无法更改标签颜色或图例颜色。我想出了如何更改刻度颜色,但我不确定将“scaleFontColor”放在哪里,如果那确实是我需要使用的。

这是一个链接,指向它现在的样子。 http://imgur.com/nxaH1mk

这是我的代码:

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
scaleFontColor: "white",
type: "bar",
data: {
labels: <?php echo json_encode($timeSlice); ?>,
datasets: [{
label: "A Label",
backgroundColor: "rgba(159,170,174,0.8)",
borderWidth: 1,
hoverBackgroundColor: "rgba(232,105,90,0.8)",
hoverBorderColor: "orange",
scaleStepWidth: 1,
data: <?php echo json_encode($myCount); ?>
}]
},
options: {
legend: {
fontColor: "white"
},
scales: {
yAxes: [{
ticks: {
fontColor: "white",
stepSize: 1,
beginAtZero: true
}
}]
}
}
});

如有任何帮助,我们将不胜感激。

最佳答案

呃,我解决了,很抱歉这个问题。但我想我会留下答案,以防其他人遇到我的问题。

var ctx = document.getElementById("barChart");
var myChart = new Chart(ctx, {
type: "bar",
data: {
labels: ["label 1", "label 2"],
datasets: [{
label: "My Label",
backgroundColor: "rgba(159,170,174,0.8)",
borderWidth: 1,
hoverBackgroundColor: "rgba(232,105,90,0.8)",
hoverBorderColor: "orange",
scaleStepWidth: 1,
data: [4, 5]
}]
},
options: {
legend: {
labels: {
fontColor: "blue",
fontSize: 18
}
},
scales: {
yAxes: [{
ticks: {
fontColor: "green",
fontSize: 18,
stepSize: 1,
beginAtZero: true
}
}],
xAxes: [{
ticks: {
fontColor: "purple",
fontSize: 14,
stepSize: 1,
beginAtZero: true
}
}]
}
}
});
   <!-- Edit:
chart.js recently released new version v3.x
which is not backwards compatible with v2.x
-->

<!--<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>-->

<!-- above link gets you latest version of chart.js (at v3.3.2 now)
hence snippet didn't work propperly anymore :-(
-->

<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4"></script>

<!-- above link gets you v2.9.4
and snippet works agian :-)
-->

<div>
<canvas id="barChart" height="140"></canvas>
</div>

关于javascript - Chart.js 标签颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37292423/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com