google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var charts = {};
var options = {
Column: {
chartArea: {
height: '100%',
width: '100%',
top: 24,
left: 64,
right: 32,
bottom: 48,
},
tooltip: {
valueDecimals: 2,
valueSuffix: ' USD',
valuePrefix: '$'
},
'vAxis': {
title: 'Cost in USD ($)', format:'$#',
},
height: '100%',
legend: {
position: 'bottom'
},
pointSize: 4,
width: '100%'
},
};
// columns charts data
var jsonData = [["2017-01-01", 83578], ["2017-02-01", 208529], ["2017-03-01", 211377], ["2017-04-01", 215149], ["2017-05-01", 215149]];
loadData(jsonData, '1', 'Line');
var data2 = [["2017-02-01", 332], ["2017-03-01", 341], ["2017-04-01", 339], ["2017-05-01", 339]];
// load json data
function loadData(jsonData, id, chartType) {
// create data table
var dataTable = new google.visualization.DataTable();
switch (chartType) {
case 'Line':
var chartData = [];
chartData.push(['date', 'Cost']);
jsonData.forEach(function (row) {
chartData.push([row[0], parseFloat(row[1])]);
});
var dataTable = google.visualization.arrayToDataTable(chartData);
// drawChart();
// var chartData = [];
// chartData.push(['date', 'Cost']);
// data2.forEach(function (row) {
// chartData.push([row[0], parseFloat(row[1])]);
// });
//var dataTable = google.visualization.arrayToDataTable(chartData);
//var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1], [1]);
break;
}
// draw chart
$(window).resize(function () {
drawChart(id, chartType, dataTable);
});
drawChart(id, chartType, dataTable);
}
// draw chart
function drawChart(id, chartType, dataTable) {
if (!charts.hasOwnProperty(id)) {
charts[id] = new google.visualization.ChartWrapper({
chartType: chartType + 'Chart',
containerId: 'chart-' + id,
options: options[chartType]
});
}
charts[id].setDataTable(dataTable);
charts[id].draw();
}
});
html, body {
height: 100%;
margin: 0px 0px 0px 0px;
overflow: hidden;
padding: 0px 0px 0px 0px;
}
.chart {
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div class="chart" id="chart-1"></div>