gpt4 book ai didi

javascript - 我可以同步两个不同年份(闰年)的 highcharts 系列吗

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:48 27 4
gpt4 key购买 nike

问题在以下 fiddle 中得到了最好的描述: https://jsfiddle.net/bernhard_kern/85s2fm5a/3/ .我们使用两个系列和两个 xAxis。

xAxis: [{
type: 'datetime',
min: new Date('2016/02/22').getTime(),
max: new Date('2016/03/05').getTime()

}, {
type: 'datetime',
min: new Date('2015/02/22').getTime(),
max: new Date('2015/03/06').getTime()
}],

我想比较年度时间序列,由于闰年(2016 年,2 月 29 日),它们具有不同数量的值

Requirement: Display the equal dates below each other, even if there is a leap year.

在示例中,您可以看到 3 月 1 日显示在 2 月 29 日下方。对于非闰年时间序列应该有一个差距。即使我在 3 月 1 日添加了一个空值,我也无法停止房间时间连续体

有人可以帮帮我吗?

最佳答案

我会这样处理:

1) 使用单个 x 轴,点开始使用当前年份(或者,无论哪一年是闰年,以确保您可以考虑闰日。哪一年都没有关系在这里使用,只要它是闰年。你可以使用 1976 对最终结果没有影响)

2)在闰日的日期,在没有闰日的数据系列中,插入一个空值

3) 使用系列名称来表示所讨论的年份,并在工具提示(和/或您需要显示日期的任何其他地方)中格式化日期以返回不带年份的格式。

代码示例:

  $('#container').highcharts({
chart: {
renderTo: 'container'
},
plotOptions: {
series: {
pointStart: Date.UTC(2016, 1, 22),
pointInterval: 24 * 3600 * 1000 // one day
}
},
tooltip: {
shared: true,
crosshairs: true,
dateTimeLabelFormats : {
day:"%b %e"
}
},
xAxis: {
type: 'datetime'
},
series: [{
name: '2015',
data: [176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, null, 71.5, 106.4, 129.2, 144.0],
},{
name:'2016',
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
}]
});

fiddle :

关于javascript - 我可以同步两个不同年份(闰年)的 highcharts 系列吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35748588/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com