How to create a grouped waterfall chart in amchart?
up vote
0
down vote
favorite
I would like to create a grouped waterfall chart using AmCharts.
My data would have two dimensions for the category and 1 dimension for the value.
For example , say I have "Year" as my categoryPath and "Cost" to be my valuePath. I want the "Year" field to display as the total cost for that year. Then I have an extra field called "Items" that will be the increasing/decreasing values(floating columns). How would I go about in achieving this?
This is my data : https://api.myjson.com/bins/s6652;
I am using amCharts version 3. I have assigned the open and close values like so :
var dNest = d3.nest()
.key(function (d) { return d["Year"]; })
.entries(rawData);
dNest.forEach(function (d) {
d["Year"] = d.key;
d.children = d.values;
delete d["Year"];
delete d.key;
delete d.values;
});
var totalValue = 0;
for (var i = 0; i < dNest.length; i++) {
dNest[i].children.forEach(function (d, j) {
totalValue += d["Cost"];
if (i == 0 && j == 0) {
d.open = 0;
d.close = d.open + d["Cost"];//parseFloat(d.open + totalValue).toFixed(2);
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
else {
d.open = dNest[i].children[j - 1].close;
d.close = d.open + d["Cost"];
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
})
}
Amchart settings
var settings = {
type: "serial",
theme: "light",
dataProvider: transformedData,
legend: {
data: [{ title: "Increasing", color: "#54cb6a" }, { title: "Decreasing", color: "#cc4b48" }]
},
valueAxes: valueAxe,
startDuration: 1,
graphs: [
{
balloonText: "<span style='color:[[color]]'>[[category]]</span><br><b>$[[balloonValue]]</b>",
colorField: "color",
fillAlphas: 0.8,
labelText: "$[[balloonValue]]",
lineColor: "#BBBBBB",
openField: "open",
type: "column",
valueField: "close",
adaptiveLabelPosition: true
}
],
trendLines: trendLines,
columnWidth: 0.6,
categoryField: xPath,
categoryAxis: {
gridPosition: "start",
axisAlpha: 0,
gridAlpha: 0.1,
labelRotation: 45
},
export: {
enabled: true
}
};
}
First I nest it to group all of it together. Unfortunately AmCharts don't support nested JSON data. So how do I flatten all the children into its parent and obtain my expected output?
sample output is something like this :

javascript d3.js amcharts
add a comment |
up vote
0
down vote
favorite
I would like to create a grouped waterfall chart using AmCharts.
My data would have two dimensions for the category and 1 dimension for the value.
For example , say I have "Year" as my categoryPath and "Cost" to be my valuePath. I want the "Year" field to display as the total cost for that year. Then I have an extra field called "Items" that will be the increasing/decreasing values(floating columns). How would I go about in achieving this?
This is my data : https://api.myjson.com/bins/s6652;
I am using amCharts version 3. I have assigned the open and close values like so :
var dNest = d3.nest()
.key(function (d) { return d["Year"]; })
.entries(rawData);
dNest.forEach(function (d) {
d["Year"] = d.key;
d.children = d.values;
delete d["Year"];
delete d.key;
delete d.values;
});
var totalValue = 0;
for (var i = 0; i < dNest.length; i++) {
dNest[i].children.forEach(function (d, j) {
totalValue += d["Cost"];
if (i == 0 && j == 0) {
d.open = 0;
d.close = d.open + d["Cost"];//parseFloat(d.open + totalValue).toFixed(2);
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
else {
d.open = dNest[i].children[j - 1].close;
d.close = d.open + d["Cost"];
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
})
}
Amchart settings
var settings = {
type: "serial",
theme: "light",
dataProvider: transformedData,
legend: {
data: [{ title: "Increasing", color: "#54cb6a" }, { title: "Decreasing", color: "#cc4b48" }]
},
valueAxes: valueAxe,
startDuration: 1,
graphs: [
{
balloonText: "<span style='color:[[color]]'>[[category]]</span><br><b>$[[balloonValue]]</b>",
colorField: "color",
fillAlphas: 0.8,
labelText: "$[[balloonValue]]",
lineColor: "#BBBBBB",
openField: "open",
type: "column",
valueField: "close",
adaptiveLabelPosition: true
}
],
trendLines: trendLines,
columnWidth: 0.6,
categoryField: xPath,
categoryAxis: {
gridPosition: "start",
axisAlpha: 0,
gridAlpha: 0.1,
labelRotation: 45
},
export: {
enabled: true
}
};
}
First I nest it to group all of it together. Unfortunately AmCharts don't support nested JSON data. So how do I flatten all the children into its parent and obtain my expected output?
sample output is something like this :

javascript d3.js amcharts
Requirement is still unclear. Do you have any other charting library link that has fulfill your requirement or elaborate your requirement more.
– front_end_dev
56 mins ago
This example by Anychart is also pretty accurate. anychart.com/products/anychart/gallery/Waterfall_Charts/…
– Syed Ariff
29 mins ago
Anychart has a property called isTotal for its total columns but AmCharts does not. How do I achieve this using Amchart? @front_end_dev
– Syed Ariff
28 mins ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to create a grouped waterfall chart using AmCharts.
My data would have two dimensions for the category and 1 dimension for the value.
For example , say I have "Year" as my categoryPath and "Cost" to be my valuePath. I want the "Year" field to display as the total cost for that year. Then I have an extra field called "Items" that will be the increasing/decreasing values(floating columns). How would I go about in achieving this?
This is my data : https://api.myjson.com/bins/s6652;
I am using amCharts version 3. I have assigned the open and close values like so :
var dNest = d3.nest()
.key(function (d) { return d["Year"]; })
.entries(rawData);
dNest.forEach(function (d) {
d["Year"] = d.key;
d.children = d.values;
delete d["Year"];
delete d.key;
delete d.values;
});
var totalValue = 0;
for (var i = 0; i < dNest.length; i++) {
dNest[i].children.forEach(function (d, j) {
totalValue += d["Cost"];
if (i == 0 && j == 0) {
d.open = 0;
d.close = d.open + d["Cost"];//parseFloat(d.open + totalValue).toFixed(2);
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
else {
d.open = dNest[i].children[j - 1].close;
d.close = d.open + d["Cost"];
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
})
}
Amchart settings
var settings = {
type: "serial",
theme: "light",
dataProvider: transformedData,
legend: {
data: [{ title: "Increasing", color: "#54cb6a" }, { title: "Decreasing", color: "#cc4b48" }]
},
valueAxes: valueAxe,
startDuration: 1,
graphs: [
{
balloonText: "<span style='color:[[color]]'>[[category]]</span><br><b>$[[balloonValue]]</b>",
colorField: "color",
fillAlphas: 0.8,
labelText: "$[[balloonValue]]",
lineColor: "#BBBBBB",
openField: "open",
type: "column",
valueField: "close",
adaptiveLabelPosition: true
}
],
trendLines: trendLines,
columnWidth: 0.6,
categoryField: xPath,
categoryAxis: {
gridPosition: "start",
axisAlpha: 0,
gridAlpha: 0.1,
labelRotation: 45
},
export: {
enabled: true
}
};
}
First I nest it to group all of it together. Unfortunately AmCharts don't support nested JSON data. So how do I flatten all the children into its parent and obtain my expected output?
sample output is something like this :

javascript d3.js amcharts
I would like to create a grouped waterfall chart using AmCharts.
My data would have two dimensions for the category and 1 dimension for the value.
For example , say I have "Year" as my categoryPath and "Cost" to be my valuePath. I want the "Year" field to display as the total cost for that year. Then I have an extra field called "Items" that will be the increasing/decreasing values(floating columns). How would I go about in achieving this?
This is my data : https://api.myjson.com/bins/s6652;
I am using amCharts version 3. I have assigned the open and close values like so :
var dNest = d3.nest()
.key(function (d) { return d["Year"]; })
.entries(rawData);
dNest.forEach(function (d) {
d["Year"] = d.key;
d.children = d.values;
delete d["Year"];
delete d.key;
delete d.values;
});
var totalValue = 0;
for (var i = 0; i < dNest.length; i++) {
dNest[i].children.forEach(function (d, j) {
totalValue += d["Cost"];
if (i == 0 && j == 0) {
d.open = 0;
d.close = d.open + d["Cost"];//parseFloat(d.open + totalValue).toFixed(2);
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
else {
d.open = dNest[i].children[j - 1].close;
d.close = d.open + d["Cost"];
d.balloonValue = parseFloat(d.close - d.open).toFixed(2);
}
})
}
Amchart settings
var settings = {
type: "serial",
theme: "light",
dataProvider: transformedData,
legend: {
data: [{ title: "Increasing", color: "#54cb6a" }, { title: "Decreasing", color: "#cc4b48" }]
},
valueAxes: valueAxe,
startDuration: 1,
graphs: [
{
balloonText: "<span style='color:[[color]]'>[[category]]</span><br><b>$[[balloonValue]]</b>",
colorField: "color",
fillAlphas: 0.8,
labelText: "$[[balloonValue]]",
lineColor: "#BBBBBB",
openField: "open",
type: "column",
valueField: "close",
adaptiveLabelPosition: true
}
],
trendLines: trendLines,
columnWidth: 0.6,
categoryField: xPath,
categoryAxis: {
gridPosition: "start",
axisAlpha: 0,
gridAlpha: 0.1,
labelRotation: 45
},
export: {
enabled: true
}
};
}
First I nest it to group all of it together. Unfortunately AmCharts don't support nested JSON data. So how do I flatten all the children into its parent and obtain my expected output?
sample output is something like this :

javascript d3.js amcharts
javascript d3.js amcharts
edited 10 mins ago
asked 1 hour ago
Syed Ariff
3431317
3431317
Requirement is still unclear. Do you have any other charting library link that has fulfill your requirement or elaborate your requirement more.
– front_end_dev
56 mins ago
This example by Anychart is also pretty accurate. anychart.com/products/anychart/gallery/Waterfall_Charts/…
– Syed Ariff
29 mins ago
Anychart has a property called isTotal for its total columns but AmCharts does not. How do I achieve this using Amchart? @front_end_dev
– Syed Ariff
28 mins ago
add a comment |
Requirement is still unclear. Do you have any other charting library link that has fulfill your requirement or elaborate your requirement more.
– front_end_dev
56 mins ago
This example by Anychart is also pretty accurate. anychart.com/products/anychart/gallery/Waterfall_Charts/…
– Syed Ariff
29 mins ago
Anychart has a property called isTotal for its total columns but AmCharts does not. How do I achieve this using Amchart? @front_end_dev
– Syed Ariff
28 mins ago
Requirement is still unclear. Do you have any other charting library link that has fulfill your requirement or elaborate your requirement more.
– front_end_dev
56 mins ago
Requirement is still unclear. Do you have any other charting library link that has fulfill your requirement or elaborate your requirement more.
– front_end_dev
56 mins ago
This example by Anychart is also pretty accurate. anychart.com/products/anychart/gallery/Waterfall_Charts/…
– Syed Ariff
29 mins ago
This example by Anychart is also pretty accurate. anychart.com/products/anychart/gallery/Waterfall_Charts/…
– Syed Ariff
29 mins ago
Anychart has a property called isTotal for its total columns but AmCharts does not. How do I achieve this using Amchart? @front_end_dev
– Syed Ariff
28 mins ago
Anychart has a property called isTotal for its total columns but AmCharts does not. How do I achieve this using Amchart? @front_end_dev
– Syed Ariff
28 mins ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203375%2fhow-to-create-a-grouped-waterfall-chart-in-amchart%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Requirement is still unclear. Do you have any other charting library link that has fulfill your requirement or elaborate your requirement more.
– front_end_dev
56 mins ago
This example by Anychart is also pretty accurate. anychart.com/products/anychart/gallery/Waterfall_Charts/…
– Syed Ariff
29 mins ago
Anychart has a property called isTotal for its total columns but AmCharts does not. How do I achieve this using Amchart? @front_end_dev
– Syed Ariff
28 mins ago