I am attempting to recreate a nvd3.js multiBar Chart using my own .csv data. While I have come across similar questions in the past, none of them have provided a solution specific to my current issue. Some suggestions involve utilizing d3.entries, d3.nest, and creating variables to achieve the correct input format. However, I am struggling to understand how these techniques work.
Related questions: d3.js csv to nvd3 (stacked area chart) format ScatterChart in NVD3 – Reading the data from csv file d3 csv data loading
These inquiries focus on replicating other types of charts that require different JSON data formats. My main struggle lies in generating the "x" and "y" values within the nest function. In the example chart, they utilize a function to create data where they define the x (number of bars) and y (input values).
I aim to replicate this graph:
Using the following csv data:
date,Equipment:Electricity:LGF,Equipment:Electricity:GF,Equipment:Electricity:1st,Equipment:Electricity:2nd
jan,6726.864146,5648.080727,2598.709507,2042.260163
feb,6405.091236,5377.910358,2474.402801,1944.570663
mar,6727.448125,5648.571054,2598.935109,2042.437457
apr,6433.12227,5401.446071,2485.231698,1953.080819
may,6993.742947,5872.160325,2701.809623,2123.28394
jun,6433.12227,5401.446071,2485.231698,1953.080819
jul,6727.448125,5648.571054,2598.935109,2042.437457
aug,6993.742947,5872.160325,2701.809623,2123.28394
sep,6166.827448,5177.8568,2382.357183,1872.234336
oct,6993.742947,5872.160325,2701.809623,2123.28394
nov,6699.417092,5625.035342,2588.106212,2033.927301
dec,6167.411428,5178.347127,2382.582785,1872.411631
The expected data should follow this JSON format (actual version contains more data):
[
{
"key": "Stream #0",
"values": [
{
"x": 0,
"y": 0.4428573444644372
},
{
"x": 1,
"y": 1.1148710782512004
},
{
"x": 2,
"y": 1.4665579659689634
}
]
},
{
"key": "Stream #1",
"values": [
{
"x": 0,
"y": 0.14053699714131654
},
{
"x": 1,
"y": 0.1493057878687978
},
{
"x": 2,
"y": 0.12193947387887433
}
]
}
]
I have experimented with various solutions from related questions, resulting in outputs like this: https://i.sstatic.net/k5dh8.png. Here, you can see my attempt on the left based on an example, and on the right is the loaded JSON file.
CODE:
Any hints or explanations would be greatly appreciated!