2 回答
TA贡献1772条经验 获得超6个赞
是的。你可以。我修改了您的代码以获得如下所示的输出。
这是带有 demo的完整代码。
您必须在比例尺中添加一个配置回调来更新 x 轴的参数。
这是代码。
*注意:请同时关注min,max和step size。
//Labels for your x-axis
var xLabels = {
20: 'No Complexity',
40: 'Below Average',
60: 'Average',
80: 'Above Average',
100: 'Highly Focused',
120: 'Extraordinarily Focused'
}
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
// The type of chart you want to create
type: 'horizontalBar',
// The data for your dataset
data: {
labels: ["Individual Thinking", "Individual Feeling", "Individual Doing",
"Partner Thinking", "Partner Feeling", "Partner Doing",
"Team Thinking", "Team Feeling", "Team Doing",
"Cultural Thinking", "Cultural Feeling", "Cultural Doing"
],
datasets: [{
label: 'Dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [27, 25, 50, 45, 110, 62, 30, 100, 56, 28, 87, 30, 71, 23]
}]
},
// Configuration options go here
options: {
scales: {
xAxes: [{
ticks: {
callback: function(value, index, values) {
return xLabels[value];
},
beginAtZero: true,
min: 20, //The minimum value in the data range
max: 120, //The maximum value in the data range
stepSize: 20, //The gap between each x-axis index
}
}]
}
}
});
<canvas id="myChart"></canvas>
添加回答
举报