Alban_T
Posts: 11
Joined: Mon May 16, 2016 2:21 pm

using javascript

Hi,

It's easier to show than to explain I think :)

I'm trying to do something like this:

Code: Select all

Highcharts.chart('container', {
    xAxis: {
        plotBands: [{ 
            color: '#FCFFC5',
            from: function() {
               var MinDate = new Date(1539182943000);
               return Date.UTC(MinDate.getFullYear(),MinDate.getMonth() ,MinDate.getDate() ,6,0,0);
           },
           to: function() {
            	var MinDate = new Date(1539182943000);
            	return Date.UTC(MinDate.getFullYear(),MinDate.getMonth() ,MinDate.getDate()+2 ,22,0,0);
           },
        }],
        tickInterval: 24 * 3600 * 1000, // one day
        type: 'datetime'
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],
        pointStart: Date.UTC(2018, 9, 9),
        pointInterval: 24 * 3600 * 1000
    }]
});
Obviously I'm not understandin ghow to do it or it would have worked I guess :(
I want to make plotbands based on a given unix timestamp.
How can I do this?
wojtek
Posts: 433
Joined: Tue Jul 03, 2018 12:32 pm

Re: using javascript

Hi Alban_T,

You added functions to plotBands from and to but they are never invoked. Wrap them getting IIFE and you are done:

Code: Select all

Highcharts.chart('container', {
  xAxis: {
    plotBands: [{
      color: '#FCFFC5',
      from: (function() {
        var MinDate = new Date(1539182943000);
        return Date.UTC(MinDate.getFullYear(), MinDate.getMonth(), MinDate.getDate(), 6, 0, 0);
      })(),
      to: (function() {
        var MinDate = new Date(1539182943000);
        return Date.UTC(MinDate.getFullYear(), MinDate.getMonth(), MinDate.getDate() + 2, 22, 0, 0);
      })(),
    }],
    tickInterval: 24 * 3600 * 1000, // one day
    type: 'datetime'
  },

  series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],
    pointStart: Date.UTC(2018, 9, 9),
    pointInterval: 24 * 3600 * 1000
  }]
});
Kind regards.
Wojciech Chmiel
Highcharts Developer
Alban_T
Posts: 11
Joined: Mon May 16, 2016 2:21 pm

Re: using javascript

Thanks for the very fast response!!!
Glad to see my idea wasn't completely wrong...
wojtek
Posts: 433
Joined: Tue Jul 03, 2018 12:32 pm

Re: using javascript

You're welcome :wink:
Wojciech Chmiel
Highcharts Developer

Return to “Highcharts Usage”