[英]ChartJS padding from lines left and right
Thanks for both the suggestions but that didn't do the trick.感谢您的建议,但这并没有解决问题。 After a lot of trial and error I found the solution:
经过大量的反复试验,我找到了解决方案:
plugins: [{
afterUpdate: function(chart) {
var dataset = chart.config.data.datasets[0];
var offset = 12;
// Blue offset left and right
var dataset = chart.config.data.datasets[1];
for (var i = 0; i < 6; i++) {
var model = dataset._meta[0].data[i]._model;
if ((i + 1) == 6){
model.x -= offset;
} else {
model.x += offset;
}
model.controlPointNextX += offset;
model.controlPointPreviousX += offset;
}
}
}],
I have put it right under the data: {}, and before options: {}.我已将其放在数据下方:{} 和选项之前:{}。
Hope I help someone with this answer, Cheers, Chris希望我能帮助别人回答这个问题,干杯,克里斯
You can fix this by adding a bit of padding to the left and right side of your chart in the options object like so:您可以通过在选项 object 中在图表的左侧和右侧添加一些填充来解决此问题,如下所示:
options: {
layout: {
padding: {
right: 100,
left: 100
}
},
}
You will need to change the numbers so it is a small change but big enough that your chart shows correctly您将需要更改数字,所以这是一个很小的变化,但足够大,您的图表可以正确显示
options:{
scales:{
xAxes:[{
offset: true
}]
}
}
The chart you shared seems to have an offset as well as xvalues with corresponding null values您共享的图表似乎具有偏移量以及具有相应 null 值的 xvalues
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.