Here is my original dataset...
[{
month: 'Jan',
cat: 'A',
val: 20
},{
month: 'Jan',
cat: 'B','
val: 5
},{
month: 'Jan',
cat: 'C',
val: 10
},{
month: 'Feb',
cat: 'A',
val: 30
},{
month: 'Feb',
cat: 'B',
val: 10
},{
month: 'Feb',
cat: 'C',
val: 20
}];
I want to convert it to the following structure..
[{
dim:'val'
x: 'Jan',
nval: 20 //same as base object val
},{
dim:'val'
x: 'Jan',
nval: 25// 20+5 -> above nval value + base object val
},{
dim:'val'
x: 'Jan',
nval: 35//25+10
},{
dim:'val'
x: 'Feb',
val: 65//35+30
},{
dim:'val'
x: 'Feb',
nval: 75
},{
dim:'val'
x: 'Feb',
nval: 95
}];
The new array in JavaScript has a fixed property dim with the value 'val'. The property x takes the value from the base object's month. The nval property in each object starts with the base object's val and then gets incremented by the base object's val in the previous object.
If you need further clarification, feel free to ask any questions.
I believe I can create the new JavaScript array using the map function, but I'm not sure about calculating and adding the values for nval based on the values of val.
Any assistance would be greatly appreciated.
Thank you!