I have a date range picker that fires a start and end date. I'm trying to update 2 charts after the start/end dates have been updated. I'm not sure exactly how to pass and parse the date variables from my getJSON call jquery call.
JSON:
{
"bar": {
"bar1": {
"x": "1/1/2014",
"a": "9",
"b": "6"
},
"bar2": {
"x": "1/2/2014",
"a": "5",
"b": "7"
},
"bar3": {
"x": "1/3/2014",
"a": "8",
"b": "9"
},
"bar4": {
"x": "2/1/2014",
"a": "7",
"b": "9"
}
},
"barstack": {
"bar1": {
"x": "1/1/2014",
"y": "9",
"z": "6",
"a": "8"
},
"bar2": {
"x": "1/2/2014",
"y": "5",
"z": "7",
"a": "3"
},
"bar3": {
"x": "1/3/2014",
"y": "8",
"z": "9",
"a": "6"
},
"bar4": {
"x": "2/1/2014",
"y": "7",
"z": "9",
"a": "8"
}
}
}
jquery call to JSON file:
(function ($, window, undefined) {
"use strict";
$(document).ready(function ($) {
$.getJSON( "js/data.json", function( json ) {
//console.log(Object.keys(json.line).map(function(key) {return json.line[key]}));
if (typeof Morris != 'undefined') {
//Bar chart
Morris.Bar({
element: 'barchart',
axes: true,
data: Object.keys(json.bar).map(function(key) {return json.bar[key]}),
resize: true,
xkey: 'x',
ykeys: ['a', 'b'],
labels: ['myCalories','myCaloriesBurned'],
barColors: ['#558C89','#D9853B']
});
Morris.Bar({
element: 'barstacked',
data: Object.keys(json.barstack).map(function(key) {return json.barstack[key]}),
resize: true,
xkey: 'x',
ykeys: ['y', 'z', 'a'],
labels: ['Tennis', 'Golf', 'Running'],
stacked: true,
barColors: ['#558C89', '#74AFAD', '#D9853B']
});
}
});
});
})(jQuery, window);