【发布时间】:2020-05-17 06:37:32
【问题描述】:
如何将我的 x 轴上的标签移动到另一个 x 轴标签之间。似乎没有任何效果,我无法在文档中找到任何内容。有解决方法吗?我正在使用折线图时间序列。 https://www.chartjs.org/samples/latest/scales/time/financial.html
目前,我使用代码生成下图:
var cfg = {
elements:{
point: {
radius: 4
}
},
data: {
datasets: [
{
label: 'vsy',
backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
borderColor: window.chartColors.red,
data: firstData,
type: 'line',
pointRadius: 2,
fill: false,
lineTension: 0,
borderWidth: 2
},
{
label: 'de vsy',
backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
borderColor: window.chartColors.blue,
data: dataMaker(15),
type: 'line',
pointRadius: 2,
fill: false,
lineTension: 0,
borderWidth: 2
}
],
},
options: {
animation: {
duration: 0
},
scales: {
xAxes: [{
type: 'time',
distribution: 'series',
offset: true,
time: {
unit: 'month',
displayFormats: {
month: 'MMM'
}
},
ticks: {
autoSkip: true,
autoSkipPadding: 75,
sampleSize: 100
},
}],
yAxes: [{
gridLines: {
drawBorder: false
}
}]
},
tooltips: {
intersect: false,
mode: 'index',
}
}
};
感谢uminder,他的评论解决了这个问题,但现在我有一个冲突的工具提示,它位于同一个网格上。当我将鼠标悬停在 4 月线的第一个点时,它会显示 3 月 30 日,它就在它的上方,反之亦然。
【问题讨论】:
标签: javascript charts chart.js chartjs-2.6.0