Home forums Using CanvasJS Graph a CSV file Reply To: Graph a CSV file

#14069

lcoulon
Member

Hello

I have a CSV file with datetime timestamps (in milliseconds from 1970) as X axis separed tis a comma ‘,’ and an associated Temperature value as Y axis.

ie :

1485097200000,22.5
1485098100000,23.8
1485099000000;24.2
etc …

From that kind of CSV file i would like to generate a google graph code like this :


<script type='text/javascript' src='http://www.google.com/jsapi'></script>

<script type='text/javascript'>

google.load('visualization', '1', {'packages':['annotatedtimeline']});
google.setOnLoadCallback(drawChart);

function drawChart() {

    var data = new google.visualization.DataTable();
    data.addColumn('datetime', 'Date');
    data.addColumn('number', 'Temperatures');
    data.addRows([
        [new Date(1485097200000), 22.5],
        [new Date(1485098100000), 23.8],
        [new Date(1485099000000), 24.2],
        // ...

        ]);

    var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
    chart.draw(data, {displayAnnotations: true});

    }
</script>

Would you please tell if it is possible and how i could do it, i’m newbie.
https://jsfiddle.net/99guxm3b/5/
Regards,