i have following javascript linechart checks out using jshint refuses display:
// load linechart charting package google.load("visualization", "1", { packages: ["corechart", "line", "linechart"] }); // set callback run when google visualization api loaded. google.setonloadcallback(drawchart); // callback creates , populates data table, // instantiates line chart, passes in data , // draws it. function drawchart() { var data = google.visualization.datatable(); data.addcolumn('date', 'date'); data.addcolumn('number', 'sales'); data.addrows([ [new date(2015, 2, 30), 419.5], [new date(2015, 2, 31), 497.51], [new date(2015, 3, 1), 1465.85], [new date(2015, 3, 2), 2594.71], [new date(2015, 3, 4), 2620.7], [new date(2015, 3, 5), 3189.86], [new date(2015, 3, 6), 4172.96], [new date(2015, 3, 7), 4332.96], [new date(2015, 3, 8), 4653.03], [new date(2015, 3, 9), 4678.98], [new date(2015, 3, 12), 5626.48], [new date(2015, 3, 13), 9779.28], [new date(2015, 3, 14), 10428.3], [new date(2015, 3, 15), 10647.18], [new date(2015, 3, 17), 10815.58], [new date(2015, 3, 20), 11471.58], [new date(2015, 3, 21), 11875.57], [new date(2015, 3, 22), 12052.07], [new date(2015, 3, 23), 13461.14], [new date(2015, 3, 24), 14072.78], [new date(2015, 3, 25), 14199.78], [new date(2015, 3, 27), 14320.28], [new date(2015, 4, 27), 100000] ]); var options = {}; // instantiate , draw our chart, passing in options. var chart = new google.visualization.linechart(document.getelementbyid('chart_div')); chart.draw(data, options); }
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['corechart', 'timeline','linechart']}]}"> </script> <div id="chart_div"></div>
so, doing wrong? have attempted several date construction methods including:
[new date('2015-3-30'), 419.5],
looks you're missing new
keyword before instantiating datatable
, can seen error message in console. also, there's typo when adding rows. should addrows
instead of addrows
.
try changing
var data = google.visualization.datatable(); // ... data.addrows([ // ...
var data = new google.visualization.datatable(); // ... data.addrows([ // ...