Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts graph X-axis label for different date ranges

I have written a below code which generates a area graph for selected dates (to and from dates).

$(document).ready(function() {
    var options = {
        "series": [{
            "showInLegend": false,
            "color": "#D0D0D0",
            "name": "Revenue",
            "data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}],
        "credits": {
            "enabled": false
        },
        "chart": {
            "renderTo": "highchart_id",
            "defaultSeriesType": "area",
            "shadow": true
        },
        "title": {
            "text": null,
            "align": "center",
            "x": 0,
            "y": 20
        },
        "xAxis": {
            "type": "datetime",
            "dateTimeLabelFormats": {
                "month": "%e. %b",
                "year": "%b"
            },
            "labels": {
                "enabled": "false"
            }
        },
        "legend": {
            "enabled": true
        },
        "yAxis": {
            "title": {
                "text": ""
            },
            "labels": {
                "enabled": true
            }
        },
        "plotOptions": {
            "area": {
                "stacking": "normal",
                "lineColor": "#3E3E3E",
                "lineWidth": 3,
                "marker": {
                    "lineWidth": "1",
                    "lineColor": "#3E3E3E",
                    "states": {
                        "hover": {
                            "enabled": true,
                            "radius": 1
                        }
                    }
                }
            },
            "series": {
                "pointStart": 1335823200000,
                "pointInterval": 86400000
            }
        }
    };
    var chart = new Highcharts.Chart(options);
});​

The interval of dates on x-axis is coming one day less. here the series value 2 is for 10 may whereas it is showing for 9 may in graph.

I am new to this highchart, can anybody advice the solution please and let me known if you need any more clarification on the problem.

like image 996
Jeet Singh Avatar asked Jun 12 '12 09:06

Jeet Singh


1 Answers

Try adding this code before declaring the chart

Highcharts.setOptions({      
  time: {
    useUTC: false
  }
});

By default highchart used UTC times. By adding the code above it will use the time zone of the browser.

like image 62
Ruchit Rami Avatar answered Nov 12 '22 07:11

Ruchit Rami