2

I created two simple time data charts with the same data. In the second one I switched the third and fourth data points and my chart becomes ugly.

You can see the results here: http://jsfiddle.net/EdmundoDelGusto/1j8eh2ya/

first chart:

series: [{
  data: [
    [Date.UTC(2010, 0, 1), 29.9], //1.
    [Date.UTC(2010, 0, 2), 71.5], //2.
    [Date.UTC(2010, 0, 3), 106.4], //3.
    [Date.UTC(2010, 0, 6), 129.2], //4.
    [Date.UTC(2010, 0, 7), 144.0], //5.
    [Date.UTC(2010, 0, 8), 176.0] //6.
  ]
}]

second chart:

series: [{
  data: [
    [Date.UTC(2010, 0, 1), 29.9], //1.
    [Date.UTC(2010, 0, 2), 71.5], //2.
    [Date.UTC(2010, 0, 6), 129.2], //4.    <<-switched
    [Date.UTC(2010, 0, 3), 106.4], //3.
    [Date.UTC(2010, 0, 7), 144.0], //5.
    [Date.UTC(2010, 0, 8), 176.0] //6.
  ]
}]

I want the second chart to look like the first chart without the need to order my data-series.

Is it possible, that Highcharts automatically connects the points in the order of the dates even if my data is in wrong order? Or do I have to sort my data first? Because in my term I got a big unsorted JSON array and maybe there is an easy solution to this.

Edit: seems like you can't do it, so I leave this post here, on how to sort an Json Array by Date: Sort JSON array by date key

Community
  • 1
  • 1
Edmundo Del Gusto
  • 378
  • 1
  • 4
  • 15
  • 2
    Highcharts requires that the points be in order. You can create your own function to sort your data or modify the JSON call to do it for you (if from a SQL database for example). – wergeld May 12 '16 at 16:42

1 Answers1

4

The Highcharts requires to use the sorted data by x, ascending. Unfortunately has no build-in sorting algorithm.

Sebastian Bochan
  • 37,348
  • 3
  • 49
  • 75