I am currently facing an issue while using the NVD3 library to create graphs. I am struggling to integrate a JSON URL correctly with the code provided.
Here is the script for the graph:
d3.json("jsondata3.json",function(error,data){
var chart;
nv.addGraph(function() {
chart = nv.models.linePlusBarChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.margin({top: 30, right: 20, bottom: 50, left: 175})
chart.y1Axis.tickFormat(d3.format(',f'));
chart.y2Axis.tickFormat(d3.format(',f'));
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
});
});
The format of the JSON data is as follows:
[{"TRANSACTION_DAY":"20130620","MT_ATTEMPTED":4505891,"MT_SUCCESS":83.54,"MO_ATTEMPTED":321857,"MO_SUCCESS":98.9},{"TRANSACTION_DAY":"20130621","MT_ATTEMPTED":6636631,"MT_SUCCESS":81.33,"MO_ATTEMPTED":311954,"MO_SUCCESS":98.66},{"TRANSACTION_DAY":"20130622","MT_ATTEMPTED":2708897,"MT_SUCCESS":90.47,"MO_ATTEMPTED":334279,"MO_SUCCESS":98.95} ]
The example provided includes code that utilizes a "map.series.values" function and has a slightly different formatting compared to my JSON data. I'm unsure how to adjust my JSON file to work seamlessly with this code. Any assistance would be appreciated.
var testdata = [
{
"key" : "Quantity" ,
"bar": true,
"values" : [ [ 1327986000000 , 690033.0] , [ 1330491600000 , 690033.0] , [ 1333166400000 , 514733.0] , [ 1335758400000 , 514733.0]]
},
{
"key" : "Price" ,
"values" : [ [ 1322629200000 , 382.2] , [ 1325307600000 , 405.0] , [ 1327986000000 , 456.48] , [ 1330491600000 , 542.44] , [ 1333166400000 , 599.55] , [ 1335758400000 , 583.98] ]
}
].map(function(series) {
series.values = series.values.map(function(d) { return {x: d[0], y: d[1] } });
return series;
});
If anyone can provide guidance on how to successfully align my JSON file with this code structure, it would be greatly appreciated. Thank you.