javascript-具有自定义X轴标签的Chart.js气泡图
作者:互联网
无论如何,我可以自定义X轴标签到单词而不是数字刻度吗?
我尝试在我的数据中插入labels属性,但是它不起作用.
这是我的代码:
var bubbleChartData =
{
datasets: [
{
label: "My First dataset",
backgroundColor: randomColor(),
data: [4, 2, 3, 4, 5]
}],
labels: [
"Bad",
"Average",
"Good",
"Very Good",
"Perfect"
]
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myChart = new Chart(ctx, {
type: 'bubble',
data: bubbleChartData,
xAxisID: 'testing',
options: {
responsive: true,
title:{
display: true,
text:'Chart.js Bubble Chart'
},
}
});
};
解决方法:
在xAxes中使用回调作为选项:
options: {
responsive: true,
title:{
display: true,
text:'Chart.js Bubble Chart'
},
scales: {
xAxes: [{
ticks: {
callback: function(value, index, values) {
return 'value is ' + value;
}
}
}]
}
}
标签:angularjs,chart-js,charts,javascript 来源: https://codeday.me/bug/20191118/2028940.html