我是Chart.js的新手,我一直在寻找一种方法来显示chart.js中的所有标签,无论是否有标签的数据,我已经尝试了最大值和最小值,但它不工作,所以我遇到了ticks回调:
let ctx = document.getElementById("chart").getContext("2d");
let config = {
type: "bar",
data: {
datasets: [
{
label: "cost of goods sold",
data: [0, 20, 40, 50],
},
],
//labels: ["January", "February", "March", "April"],
},
options: {
scales: {
x: {
ticks: {
callback: (value, index, ticks) => {
const x = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"october",
"November",
"December",
];
return x;
},
},
},
},
},
};
let chart = new Chart(ctx, config);
有没有办法让所有人都显示一个固定标签,比如总是显示12个月,31天,12周?
1条答案
按热度按时间mqkwyuun1#
您可以定义
data.labels
,并确保data.datasets.data
具有相同的条目数,null
表示缺少的值。第一个