Column chart
Integration with amCharts 4
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script src="https://cdn.flexmonster.com/lib/flexmonster.amcharts.js"></script>
<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>
<script src="https://cdn.amcharts.com/lib/4/themes/kelly.js"></script>
<div id="pivotContainer">The component will appear here</div>
<div id="amcharts-container"></div>
CSS
@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);
#amcharts-container {
margin: 20px;
height: 400px;
}
JavaScript
let pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
toolbar: true,
height: 430,
report: {
dataSource: {
filename: "data/data.csv",
},
slice: {
rows: [
{
uniqueName: "Country",
filter: {
exclude: ["country.[united kingdom]"],
},
},
],
columns: [
{
uniqueName: "Color",
},
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "Price",
format: "currency",
},
{
uniqueName: "Quantity",
format: "quantity",
},
],
},
formats: [
{
name: "currency",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 2,
currencySymbol: "$",
currencySymbolAlign: "left",
nullValue: "",
textAlign: "right",
isPercent: false,
},
{
name: "quantity",
thousandsSeparator: ",",
decimalPlaces: 0,
currencySymbol: " psc.",
currencySymbolAlign: "right",
nullValue: "",
textAlign: "right",
},
],
},
reportcomplete: function () {
pivot.off("reportcomplete");
createChart();
},
});
let chart;
function createChart() {
pivot.amcharts.getData({}, drawChart, updateChart);
}
function drawChart(chartConfig, rawData) {
// Apply amCharts theme
am4core.useTheme(am4themes_animated);
am4core.useTheme(am4themes_kelly);
chart = am4core.create("amcharts-container", am4charts.XYChart);
chart.data = chartConfig.data;
let categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = pivot.amcharts.getCategoryName(rawData);
...