Dawood Awan
Dawood Awan

Reputation: 7318

Time not showing correctly in HighChart

I am working with HighStock Charts.

In the DB I have UTC DateTime '2015-04-21 11:09:21.000':

enter image description here

I am cnverting this to Custom Time Zone in my Code (Should + 5 Hours in this Case):

TimeZoneInfo.ConvertTimeFromUtc(reading.dtUTCDateTime, assetCountryTimeZone);

enter image description here

As you can see below the Time in the View is correct: ie.

11:09 + 5 Hrs = 16:09

enter image description here

I then Convert the Array/List in Json:

     <script type="text/javascript">
    var avgCustomArray2 = @Html.Raw(Json.Encode(avgCustomArray2));

// Display first
        var re = /-?\d+/;
 for (var i = 0; i < avgCustomArray2.length; i++) {
                    var m = re.exec(avgCustomArray2[i].date);

                    if (i == 0) {
                        console.log(new Date(parseInt(m[0])));
                        console.log(parseInt(m[0]));
                    }

// Removed Code from here:

}

    </script>

And in the Console.log()

I get the correct DateTime: Tue Apr 21 2015 16:09:21 GMT+0100 (GMT Daylight Time)

and in milliseconds: 1429628961000 Still (16:09) http://jsfiddle.net/3wux78tL/

So when I plot the Graph, I get the wrong time it is (15:09): Which is 1 hour less than the correct value

enter image description here

This is the HighChart Code setup:

 $("#container").highcharts("StockChart", {
                    chart: { zoomType: "x" },
                    rangeSelector: { enabled: false },
                    legend: { enabled: true },
                    yAxis: [
                        {
                            tickInterval: 0.5,
                            min: 0
                        }
                    ],
                    xAxis: [
                        {
                            title: { text: "Time " },
                            type: 'datetime'
                        }
                    ],
                    series: [
                        {
                            data: chartData,
                            tooltip: { valueDecimals: 2 }
                        }
                    ]
                });

enter image description here

Upvotes: 0

Views: 426

Answers (1)

Moe Bataineh
Moe Bataineh

Reputation: 1080

Refer to this: Highcharts - time off by 1 hour

Attempt to do:

Highcharts.setOptions({
    global: {
        // timezoneOffset: +1,
        useUTC: false
    }
});

Upvotes: 1

Related Questions