Hiren
Hiren

Reputation: 621

Why Highcharts not returning the proper date?

Hello i'm developing a chart similar to This Fiddle. But in that chart the dates are displayed which are not actual dates 1 Jan, 1970 And tried using formatter() also returns the first on date not full date and also removes the HTML and strings which i concatenated while returning.

Upvotes: 0

Views: 50

Answers (1)

jlbriggs
jlbriggs

Reputation: 17800

There are a number of approaches taking place in the fiddle, post, and comment thread.

Here's one that works:

tooltip: {
  formatter: function() {
    var month    = this.point.y;
    var day      = this.point.x;
    var dataDate = new Date(dataYear, month, day); //set the date object; dataYear predefined
    return  '<b>Power Generated</b><br/>'
           +Highcharts.dateFormat('%e %b, %Y', dataDate) //format the date object
           +': <b>'+this.point.value +' kWh</b>';
    }
}

Example:

Obviously, you can edit the strings in whichever way you want to.

There are a number of reasons that things were not workign with earlier versions, including:

  • the month/date being swapped in the new Date() declaration.

  • calling HighCharts instead of Highcharts

  • calling this.value instead of this.point.value

If you have more specific questions about something not working, feel free to ask.

Upvotes: 1

Related Questions