我想知道为什么我的图表没有向左对齐以及我该如何做到这一点?这是我的代码:
var data = {
labels: ["ID"]
, datasets: [
{
label: "Sensor 1"
, data: [{
x: 0
, y: 2
}, {
x: 12
, y: 5
}]
, backgroundColor: [
'rgba(255, 99, 132, 0.2)'
, ]
, borderColor: [
'rgba(255,99,132,1)'
]
, borderWidth: 1
}
]
};
var options = {
title: {
display: true
, text: 'Custom Chart Title'
}
, scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
, xAxes: [{
type: "linear"
, position: "bottom"
}]
}
};
var myLineChart = Chart.Line(ctx, {
data: data
, options: options
});
该线从图表的中心开始,但我不知道如何将其对齐到左侧(在 x 轴上)。它是这样的:
https://picload.org/image/raoipwci/chartjs.png
如您所见,另一个问题是 y 轴与我输入的数据集不匹配。
编辑:好的,我终于成功了。我添加了正确的代码。
最佳答案
我意识到这是一篇旧帖子,但我认为我已经解决了您的问题,我将把它留在这里给正在搜索此内容的其他人(我现在无法测试它,但应该是这样):
xAxes: [{
type: "linear"
, position: "bottom"
, beginAtZero: true
, min: 0
}]
有人告诉我这是否正确:)
关于javascript - Chart.js 将折线图向左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41109818/