Funnel chart
A demo of amCharts 4, the previous version. For a new project, start from the amCharts 5 demos.
Funnel Chart is used to display how the data is filtered down through the steps of some process or processes. Each step represents a portion of the total going through it. The top (head) of each step represents the incoming value and the bottom (neck) the output value after some sort of filtering.
Open in:
Code
JavaScript
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("chartdiv", am4charts.SlicedChart);
chart.hiddenState.properties.opacity = 0; // this makes initial fade in effect
chart.data = [{
"name": "The first",
"value": 600
}, {
"name": "The second",
"value": 300
}, {
"name": "The third",
"value": 200
}, {
"name": "The fourth",
"value": 180
}, {
"name": "The fifth",
"value": 50
}, {
"name": "The sixth",
"value": 20
}, {
"name": "The seventh",
"value": 10
}];
var series = chart.series.push(new am4charts.FunnelSeries());
series.colors.step = 2;
series.dataFields.value = "value";
series.dataFields.category = "name";
series.alignLabels = true;
series.labelsContainer.paddingLeft = 15;
series.labelsContainer.width = 200;
//series.orientation = "horizontal";
//series.bottomRatio = 1;
chart.legend = new am4charts.Legend();
chart.legend.position = "left";
chart.legend.valign = "bottom";
chart.legend.margin(5,5,20,5);
JSON
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.createFromConfig({
"data": [{
"name": "The first",
"value": 600
}, {
"name": "The second",
"value": 300
}, {
"name": "The third",
"value": 200
}, {
"name": "The fourth",
"value": 180
}, {
"name": "The fifth",
"value": 50
}, {
"name": "The sixth",
"value": 20
}, {
"name": "The seventh",
"value": 10
}],
"hiddenState": {
"properties": {
"opacity": 0
}
},
"series": [{
"type": "FunnelSeries",
"alignLabels": true,
"dataFields": {
"value": "value",
"category": "name"
},
"colors": {
"step": 2
}
}],
"labelsContainer": {
"paddingLeft": 15,
"width": 200
},
"legend": {
"position": "left",
"valign": "bottom",
"marginTop": 5,
"marginRight": 5,
"marginBottom": 20,
"marginLeft": 5
}
}, "chartdiv", "SlicedChart");
HTML
<div id="chartdiv"></div>
CSS
#chartdiv {
width: 100%;
height: 500px;
}
Resources
https://cdn.amcharts.com/lib/4/core.js
https://cdn.amcharts.com/lib/4/charts.js
https://cdn.amcharts.com/lib/4/themes/animated.js
All in one page
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Chart code -->
<script>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("chartdiv", am4charts.SlicedChart);
chart.hiddenState.properties.opacity = 0; // this makes initial fade in effect
chart.data = [{
"name": "The first",
"value": 600
}, {
"name": "The second",
"value": 300
}, {
"name": "The third",
"value": 200
}, {
"name": "The fourth",
"value": 180
}, {
"name": "The fifth",
"value": 50
}, {
"name": "The sixth",
"value": 20
}, {
"name": "The seventh",
"value": 10
}];
var series = chart.series.push(new am4charts.FunnelSeries());
series.colors.step = 2;
series.dataFields.value = "value";
series.dataFields.category = "name";
series.alignLabels = true;
series.labelsContainer.paddingLeft = 15;
series.labelsContainer.width = 200;
//series.orientation = "horizontal";
//series.bottomRatio = 1;
chart.legend = new am4charts.Legend();
chart.legend.position = "left";
chart.legend.valign = "bottom";
chart.legend.margin(5,5,20,5);
</script>
<!-- HTML -->
<div id="chartdiv"></div>