简体   繁体   English

我可以同步两个不同年份的高图系列(闰年)

[英]Can I sychronize two highcharts series with different years (leap year)

The problem is best described in following fiddle : https://jsfiddle.net/bernhard_kern/85s2fm5a/3/ . 这个问题最好用以下小提琴来描述: https//jsfiddle.net/bernhard_kern/85s2fm5a/3/ We use two series and two xAxis. 我们使用两个系列和两个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.). 我想比较每年的timseries,它们由于闰年(2016年2月29日)而具有不同的数值

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 . 在示例中,您可以看到2月29日下方显示3月1日 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 . 即使我在3月1日添加空值, 我也无法停止房间时间的连续性

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 ) 1)使用单个x轴,使用当前年份的pointStart(或者,无论哪一年是闰年),以确保您可以计算闰日。 这里使用的年份甚至不重要因为它是闰年。你可以使用1976而不影响最终结果

2) at the date of the leap day, in the data series that does NOT have a leap day, insert a null value 2)在闰日的日期,在没有闰日的数据系列中,插入一个空值

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. 3)使用系列名称来表示相关年份,并在工具提示中(和/或您需要显示日期的任何其他位置),格式化要返回的日期而不是年份。

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: 小提琴:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM