【发布时间】:2017-04-18 14:19:55
【问题描述】:
我正在使用 Chart.js 创建一个堆积条形图。但是,我在文档中找不到如何更改某些内容。
- 如何在 Y 轴上添加标签。
- 如何缩短 X 轴上的标签使其仅显示 前 10 个字母。
- 如何反转值的显示顺序 工具提示。
这些东西可以实现吗?
我已经标记了我要更改的内容here.
这是我的图表选项现在的样子:
var ctx = $("#newchart");
var barGraph = new Chart(ctx, {
type: 'bar',
data: chartdata,
options: {
barValueSpacing: 20,
tooltips: {
enable: true,
mode: 'label',
callbacks: {
label: function(tooltipItem, data){
var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
return datasetLabel + ': ' + Number(tooltipItem.yLabel) + ' Users';
}
}
},
responsive: true,
segmentShowStroke: true,
scales: {
xAxes: [{
display: false,
stacked: true,
ticks:{
stepSize : 10,
},
gridLines: {
lineWidth: 0,
color: "#9E9E9E"
}
}],
yAxes: [{
stacked: true,
ticks: {
min: 0,
stepSize: 10,
},
gridLines: {
lineWidth: 0,
color: "#9E9E9E"
}
}]
}
}
});
【问题讨论】:
标签: javascript jquery chart.js chart.js2