wesm
Posts: 15
Joined: Thu Jun 09, 2011 3:35 pm

Multiple x axes?

I've got a line graph with a 'datetime' type x axis. I'd like to add a second x axis to the top of the graph marking days since the origin. I've tried just making the xAxis config an array, like you can with the yAxis, but no luck. Is it possible to have more than one x axis?
hfrntt
Posts: 6393
Joined: Mon Aug 30, 2010 8:41 am
Contact: Website

Re: Multiple x axes?

Yes it is, could you set up an example of your chart on jsfiddle?
Slawek Kolodziej
Highcharts support team
wesm
Posts: 15
Joined: Thu Jun 09, 2011 3:35 pm

Re: Multiple x axes?

Thanks for the reply. Here's a simple example, just to get started:

http://jsfiddle.net/kSkYN/4427/

The documentation simply says "In case of multiple axes, the xAxis node is an array of configuration objects." If so, what's wrong with this:

Code: Select all

    xAxis: [{
        type: 'datetime',
    },{
        type: 'datetime',
        opposite: true
    }],
hfrntt
Posts: 6393
Joined: Mon Aug 30, 2010 8:41 am
Contact: Website

Re: Multiple x axes?

You have to specify the series which use this axis (http://jsfiddle.net/kSkYN/4502/) or link this axis to another (http://jsfiddle.net/kSkYN/4501/)
Slawek Kolodziej
Highcharts support team
wesm
Posts: 15
Joined: Thu Jun 09, 2011 3:35 pm

Re: Multiple x axes?

Thanks for the pointers. What I was going for was a chart with a normal date time axis on the bottom, with a second axis on the top displaying the number of days since the start of the chart. Here's how that works, for posterity:

Code: Select all

         xAxis: [{
            type: 'datetime'
         },{
            type: 'datetime',
            linkedTo: 0,
            opposite: true,
            labels: {
               formatter: function() {
                  if (this.isFirst) { me._currentStart = this.value; }
                  return Math.round((this.value - me._currentStart) / 24 * 3600 * 1000);
               }
            },
            title: { text: 'Days Since Start' }
         }],
Thanks again!

Return to “Highcharts Usage”