Skip to content

Instantly share code, notes, and snippets.

@c0debreaker
Created July 6, 2014 06:38
Show Gist options
  • Save c0debreaker/d866cbfdf5f40e315a55 to your computer and use it in GitHub Desktop.
Save c0debreaker/d866cbfdf5f40e315a55 to your computer and use it in GitHub Desktop.
function plotHourly(jsonData, chartColor) {
var parentArray = {},
loopCtr = 0,
allFieldsFromArguments = [].slice.call(arguments, 2),
chartTitle = allFieldsFromArguments.shift(), // Grabing first argument which is title
dataFields = allFieldsFromArguments,
tmpForCObjectArray = [],
rows = [],
cols = [];
jsonData.forEach(function(a) {
dataFields.forEach(function(f) {
if (loopCtr == 0) {
tmpForCObjectArray.push({ v : a[f].split('T')[1].replace(':00Z','') });
} else {
tmpForCObjectArray.push({
v: parseInt(a[f]),
f: a[f] + " inches"
});
}
loopCtr++;
})
rows.push({c : tmpForCObjectArray});
tmpForCObjectArray = []
loopCtr = 0;
})
for (var i=0; i < dataFields.length; i++) {
if (i == 0) {
cols.push({
id: dataFields[i]+"-id",
label: dataFields[i],
type: "string"
}
);
} else {
cols.push({
id: dataFields[i]+"-id",
label: dataFields[i],
type: "number"
}
);
}
}
parentArray = {
"cols": cols,
"rows": rows
}
var chart1 = {};
chart1.type = "AreaChart";
chart1.displayed = true;
chart1.data = parentArray;
chart1.options = {
displayExactValues: true,
fill: 20,
seriesType: "area",
width: 0,
height: 0,
isStacked: true,
colors: [chartColor],
vAxis: {
"title": "",
"gridlines": {
"count": -1
}
} ,
yAxis: {
"title": "June 2014",
"gridlines": {
"count": 1
}
} ,
legend: { position: 'none'}
};
chart1.formatters = {};
return chart1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment