function drawCharts () {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Date and time');
data.addColumn('number', 'Value');
// add 100 rows of pseudo-random-walk data
var val = 50, hour, minute;
for (var i = 0; i < 100; i++) {
val += ~~(Math.random() * 5) * Math.pow(-1, ~~(Math.random() * 2));
if (val < 0) {
val += 5;
}
else if (val > 100) {
val -= 5;
}
data.addRow([new Date(2013, 0, 1, i), val]);
}
// the time entered was supposed to be UTC time, but is entered as local time
// this function updates the Date objects to the proper UTC time
function localDateToUTCDate (d) {
d.setMinutes(d.getMinutes() - d.getTimezoneOffset());
}
for (var i = 0; i < data.getNumberOfRows(); i++) {
data.setValue(i, 0, localDateToUTCDate(data.getValue(i, 0)));
}
var chart = new google.visualization.ChartWrapper({
chartType: 'LineChart',
containerId: 'chart_div',
dataTable: data,
options: {
height: 400,
width: 600,
vAxis: {
minValue: 0,
maxValue: 100
}
}
});
chart.draw();
}
google.load('visualization', '1', {packages:['controls'], callback: drawCharts});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.