I'm struggling to figure out how to use List created by apex call to draw Google Line chart. Here is the list created by Apex class:
public static List<Data> getChartData() {
List<Data> data = new List<Data>();
data.add(new Data('Jul-16', 651, 19521));
data.add(new Data('Aug-16', 651, 20172));
data.add(new Data('Sep-16', 630, 20802));
data.add(new Data('Oct-16', 651, 21453));
data.add(new Data('Nov-16', 630, 22083));
data.add(new Data('Dec-16', 651, 22734);
return data;
}
public class Data {
public String name { get; set; }
public Integer data1 { get; set; }
public Integer data2 { get; set; }
public Data(String name, Integer data1, Integer data2) {
this.name = name;
this.data1 = data1;
this.data2 = data2;
}
}
And here is the JS on VF page which I'm using to render the chart.
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'A');
data.addColumn('number', 'B');
data.addColumn('number', 'C');
data.addRows([
['Jul',630,19521],
['Aug',651,20172],
['Sep',630,20802],
['Oct',651,21453],
['Nov',630,22083],
['Dec',651,22734],
]);
var options = {
height:600,
width:900,
};
var chart1 = new google.visualization.LineChart(document.getElementById('line_chart-1'));
chart1.draw(data, options);
}
I can't figure out how to replace the data.addRows
with the function to use the List from apex class (extension to VF page).
Thanks