[英]Chart.js timeseries x ticks overlapping due to weekend
I use Chart.js to plot a line chart.我使用 Chart.js 绘制折线图。 My x axis is a timeseries .我的 x 轴是timeseries 。 However, I have ticks overlapping due to weekend data.但是,由于周末数据,我的刻度重叠。
Is there any way to avoid overlapping ticks?有什么办法可以避免重叠的刻度? I used "autoskip: true" but it doesn't seem to work.我使用了“autoskip:true”,但它似乎不起作用。
Here's how my configs look like:这是我的配置的样子:
x: {
parsing: false,
type: "timeseries",
time: {
displayFormats: {
second: "HH:mm",
minute: "HH:mm",
hour: "HH:mm",
day: "MMM d",
},
tooltipFormat: "d MMM HH:mm",
},
grid: {
display: false,
},
ticks: {
autoskip: true,
},
},
And this is how the overlapping looks like:这就是重叠的样子:
You can achieve what you're looking for by writing a callback function that checks if the value
is a weekend day您可以通过编写一个检查value
是否为周末的回调函数来实现您要查找的内容
new Date(Date.parse(value)).getDay() == 1 || new Date(Date.parse(value)).getDay() == 2
If it is we just don't return it.如果是,我们只是不退货。 Otherwise we return the value without changes.否则,我们将返回值而不做任何更改。
This is how your config should look like:这就是你的配置应该是这样的:
x:{
type: 'timeseries'
time:{
unit:'day',
},
ticks:{
callback: function(value){
//if weekend dont return the tick label
if(new Date(Date.parse(value)).getDay() == 1 || new Date(Date.parse(value)).getDay() == 2 )
return
return value
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.