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 :



enter image description here










share|improve this question
























  • 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















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 :



enter image description here










share|improve this question
























  • 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













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 :



enter image description here










share|improve this question















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 :



enter image description here







javascript d3.js amcharts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































Popular posts from this blog

how to define a CAPL function taking a sysvar argument

How do I alter this code to allow abstract classes or interfaces to work over identical auto generated...

Krisenintervention