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>
添加回答
舉報