我想知道为什么我的图表不对齐左边以及我如何做到这一点?这是我的代码:
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轴与我输入的数据集不匹配。
编辑:好的,我终于开始工作了。我添加了正确的代码。
答案 0 :(得分:0)
我意识到这是一个古老的帖子,但我想我已经找到了解决问题的方法,我会把它留给其他正在搜索的人(我现在无法对其进行测试但应该是此):
xAxes: [{
type: "linear"
, position: "bottom"
, beginAtZero: true
, min: 0
}]
有人让我知道它是否正确:)
答案 1 :(得分:0)
padding: {
top: 50,
right: 10,
bottom: 50,
left: 10,
}
}
Add this object in your graph options and change the position with top, bottom, left, right