Date on x label auto added 30 days

7 views
Skip to first unread message

Phuong Doan

unread,
Jul 24, 2020, 4:13:03 AM7/24/20
to Google Visualization API

my sample code as simple as below:
--------------------------------------------------------------
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div" style="width:200px"></div>
<script>
      google.charts.load('current', {'packages':['corechart','line']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {
        var central_rates={"rows":[{"c":[{"v":"Date(2020,07,24)"},{"v":"23221"}]},{"c":[{"v":"Date(2020,07,23)"},{"v":"23220"}]},],
            "cols":[{"type":"datetime","label":"day"},{"type":"number","label":""}]};
      var data = new google.visualization.DataTable(central_rates);
                var date_long = new google.visualization.DateFormat({pattern: 'dd/MM'});
                date_long.format(data,0);
                var options = {
                    title:'Sample line chart with date label',
                    titleTextStyle:{fontSize:'0.95em'},
                    height:'100%',
                    hAxis: {slantedText:true,format:'dd/MM',},
                    vAxis: {},
                    backgroundColor: '#ecf3fe',
                    legend: 'none',
                    chartArea:{left:35,backgroundColor:'#ecf3fe',width:'100%'}
                };
                var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
                chart.draw(data, options);
    }
</script>
--------------------------------------------------------------
There're 2 point only with date labels as Date(2020,07,24)& Date(2020,07,23). But the render chart displays them as 24/08 & 23/08 respectively, meaning 1 month was added.
2020-07-24 15_11_57-chart.html.png
How can it be? Any advice is appreciated, thanks
Reply all
Reply to author
Forward
0 new messages