Real time data sorting
by amcharts
HTML
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>
<div id="chartdiv"></div>
CSS
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 14px;
}
#chartdiv {
width: 100%;
height: 500px;
}
JavaScript
/**
* --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
*
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* 2018.
*
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
*/
am4core.useTheme(am4themes_animated);
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.paddingTop = 40;
// Add data
chart.data = [{
"category": "Research",
"value": 450,
"value2": 10000
}, {
"category": "Marketing",
"value": 1200,
"value2": 7050
}, {
"category": "Distribution",
"value": 1850,
"value2": 3600
}];
// Create axes
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.grid.template.location = 0;
function createValueAxis(title, showgrid) {
// Create axis
var axis = chart.yAxes.push(new am4charts.ValueAxis());
axis.renderer.grid.template.disabled = !showgrid;
// Set up axis title
axis.title.text = title;
axis.title.fontFamily='Arial';
axis.title.fontWeight='bold';
axis.title.fontSize = 14;
return axis;
}
function createSeries(key, title, axis) {
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = key;
series.dataFields.categoryX = "category";
series.yAxis = axis;
return series;
}
createSeries(
"value",
"Series #1",
createValueAxis("Spending", true)
);
createSeries(
"value2",
"Series #2",
createValueAxis("Funding", false)
);