我找到的关于这个主题的唯一内容是 this ,但并不能真正帮助解决问题。
正如您所看到的,数据集中未设置的值被 chop 。这是因为这段代码用 undefined
填充了所有内容:
let dataSet: any = {
label: user.userName,
backgroundColor: 'rgba(0, 0, 0, 0)',
borderColor: this.getRandomColor(),
data: new Array(this.chart.data.labels.length).fill(undefined)
}
之后,我用以下代码填充数据:
data.forEach((d)=>{
let tmpDate: Date = new Date(d.date * 1000)
let insertIndex: number = this.chart.data.labels.indexOf(this.getDateString(tmpDate))
dataSet.data.splice(insertIndex, 1, d.data) // d.data is a number
})
this.chart.data.datasets.push(dataSet)
this.chart.update()
我希望它跳过未定义的值并在图表中创建一条平滑的线。
最佳答案
spanGaps
docs 中的选项应该就是您要找的。p>
关于javascript - 如何在 ChartJS 中跳过 x 轴标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55856951/