1

Just trying to plot some data via highcharts and getting some weird results.

Its 'almost' right but not quite.

I'm plotting price changes over time and have this data coming from a db. I'm turning it into the series of data and then trying to plot.

The strange thing is, highcharts are showing data into the future and plotting November 2015!!!!

I cannot see this in the date anywhere.

Please help!

Here is a snippet from the code:

{
  type: 'line',
  name: 'Competitor 6',
  data: [
    [Date.UTC(2015, 10, 22), 91],
  ]
}

This plots on the Graph as the 22nd November 2015.

Full example file is here: https://www.dropbox.com/s/auhoe00gcsizu1g/stackexchange_example.html?dl=0

Its too long to post in here!

Thanks

Alex

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
Alex Hellier
  • 435
  • 1
  • 7
  • 15

1 Answers1

1

For array purposes, month numbers in JavaScript start at 0 (January) and go up to 11 (December).

Here you're passing in a month of 10 which in JavaScript ends up as November.

new Date(Date.UTC(2015, 10, 22))
-> "Sun Nov 22 2015 00:00:00 GMT+0000 (GMT Standard Time)"

If you're wanting this to be October, you're going to have to pass in 9 instead:

new Date(Date.UTC(2015, 9, 22))
-> "Thu Oct 22 2015 01:00:00 GMT+0000 (GMT Standard Time)"

Here's a relevant question here if you want some further reading: Why does the month argument range from 0 to 11 in JavaScript's Date constructor?

Community
  • 1
  • 1
James Donnelly
  • 126,410
  • 34
  • 208
  • 218
  • @AlexHellier well arrays are indexed at 0. With the present system you can simply do: `var months = ["January", "February", ...]` and pull January using `months[0]`. If months used their real-world numbers here we'd have to add an empty item to our array: `var months = [undefined, "January", ...]`; then we could use `months[1]` to get our month. – James Donnelly Oct 22 '15 at 10:16
  • 1
    ah so like python indexes at 0 and the months are just an array and you grab form that? Makes sense in one way, but at the same time, completely counter intuitive :-) – Alex Hellier Oct 22 '15 at 10:20