Highstock highcharts irregular data gets wrong x-scale

12,107

You will need to set the xAxis.ordinal property to false, this is true by default. True value indicates the points should be placed at fixed intervals w.r.t space (pixels), and False changes points to be placed at fixed intervals w.r.t. time

xAxis: {       
    ordinal: false
}

Linear x-axis | Highstock @ jsFiddle

Share:
12,107
Putnik
Author by

Putnik

AWS Certified Solutions Architect-Associate AWS Certified SysOps Administrator-Associate 10+ years with Linux etc :) Feel free to contact me via LinkedIn https://www.linkedin.com/in/alexander-lutchko-11b556b7/

Updated on July 01, 2022

Comments

  • Putnik
    Putnik almost 2 years

    I have irregular data. Chart draws well when I use highcharts:

    $(function() {
      var chart = new Highcharts.Chart({
        chart: {
          renderTo: 'chart'
      },
      xAxis: {
        type: 'datetime'
      },
      series: [{
        name: 'Volume',
        data: chart_arr,
      }]
    });
    });
    

    http://jsfiddle.net/KnTaw/9/

    But I have a lot of data so I need to zoom on the date and choose highstock. Then a strange thing happens: the x-axis become non-linear.

    $(function() {
      var chart2 = new Highcharts.StockChart({
        chart: {
          renderTo: 'chart2'
        },
        rangeSelector: {
          selected: 0
        },
        xAxis: {
          type: 'datetime'
        },
        series: [{
          name: 'val',
          data: chart_arr,
          type : 'area',
        }]
      });
    });
    

    http://jsfiddle.net/Mc3mW/1/

    Please note that the data for half an hour range Jan 6 20:00-20:30 allocates more space than 2 days Jan 11-13. (Of course the data is the same.)

    How can I force x-axis at highstock to become linear? Or How can I enable a bottom zoom tool for highcharts? Thank you.

  • Putnik
    Putnik over 11 years
    I know about zoom bot this is not what I want. Also perhaps there is misunderstanding: I have just went to my second example and removed "type : 'area'," line. Nothing happend except chart represents data as line (not area). Is it what you really meant?
  • Pravin
    Pravin over 9 years
    Is this a correct solution for this problem also? stackoverflow.com/questions/25861690/… I tried it but it's not solving the issue.
  • Vicky Chijwani
    Vicky Chijwani about 9 years
    This option has such an odd name. Spent hours trying to get this behaviour sigh.