【发布时间】:2018-05-15 20:02:45
【问题描述】:
我想在 Chart.js 中将“你上一场比赛的进球次数”数据绘制成折线图。
我有一个 userGoalTime 数组,例如[34, 80, 90]
我有一个对手GoalTime 数组,例如[39, 42]
Y 轴将包含所有分钟,但我不想要 X 轴上的任何内容。问题是我认为 chart.js 必须用 X 轴上的东西来表示一个值(如果这有意义的话)
谁能解释一下如何仅使用 Y 轴在图表上绘制点?
尝试的解决方案:
let ctx = canvas.getContext('2d')
let lineChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['0', '1'], // I DON'T WANT THE X AXES TO REPRESENT ANYTHING
datasets: [{
label: 'For',
backgroundColor: '#85CE36',
fill: false,
showLine: showLine, // this is true
borderColor: '#85CE36',
data: userGoals // The array as described
}, {
label: 'Against',
backgroundColor: 'red',
fill: false,
showLine: showLine, // this is true
borderColor: 'red',
data: opponentGoals // The array as described
}
]
},
options: {
responsive: true,
title: {
display: true,
text: nameOfStat
},
tooltips: {
mode: 'index',
intersect: false
},
hover: {
mode: 'nearest',
intersect: true
},
elements: {
point: {
pointStyle: style
}
},
scales: {
xAxes: [{
display: false // Not really what I am looking for... This just hides the X axes but that's it
}]
}
}
})
谢谢。
【问题讨论】:
标签: javascript chart.js axes