简体   繁体   中英

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/ . 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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