我可以同步两个不同年份的闰年系列(闰年)吗? [英] Can I sychronize two highcharts series with different years (leap year)

查看:169
本文介绍了我可以同步两个不同年份的闰年系列(闰年)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题最好在以下小提琴中描述:
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()

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

我想比较每年的timseries,由于闰年(2016年2月29日),它们的值不同。


要求:
显示相等的日期,即使有闰年也是如此。

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



有人可以帮我吗?

解决方案

我会这样来处理:

1)使用单个x轴,使用当前的年份(或者,无论哪一年是闰年)的pointStart,以确保您可以考虑闰日。这里使用的年份都不重要,只要它是2)在闰日的日期,在数据系列中,可以使用1976年,但对最终结果没有影响 b
$ b 3)使用系列名称来表示有问题的年份,并在工具提示中(和/或您需要的任何其他地方)



代码示例:

  $('#container')。highcharts({
图:{
renderTo:'container'
} ,
plotOptions:{
系列:{
pointStart:Date.UTC(2016,1,22),
pointInterval:24 * 3600 * 1000 //一天

工具提示:{
共享:true,
十字线:true,
dateTimeLabelFormats:{$ b $ day:%b%e
}
},
xAxis:{
类型:'datetime'
},
系列:[{
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',
数据:[29.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4],
}]
});

小提琴:


The problem is best described in following fiddle: https://jsfiddle.net/bernhard_kern/85s2fm5a/3/. We use two series and two 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()
    }],

I want to compare yearly timseries, which have a different amount of values due to leap year (2016, 29 Feb.).

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

In the example you can see that Mar 1 is displayed below Feb 29. For the non leap year timeseries there should be a gap. Even if I add a null value on Mar 1, I cannot stop the room time continuum.

Can somebody help me?

解决方案

I would approach it this way:

1) use a single x axis, with a pointStart using the current year (or, whichever year is a leap year, to make sure you can account for the leap day. It doesn't even matter what year is used here, as long as it is a leap year. You could use 1976 with no effect on the end result)

2) at the date of the leap day, in the data series that does NOT have a leap day, insert a null value

3) use series name to denote the year in question, and in the tooltip (and/or anywhere else that you need to display the date), format the date to return without the year.

Code example:

  $('#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:

这篇关于我可以同步两个不同年份的闰年系列(闰年)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆