Pie chart
Integration with Google Charts
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script src="https://cdn.flexmonster.com/lib/flexmonster.googlecharts.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="pivot-container"></div>
<div id="googlechart-container" style="height:250px;"></div>
CSS
@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);
#googlechart-container {
margin-top: 20px;
}
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
toolbar: true,
height: 400,
report: {
dataSource: {
filename: "data/data.csv"
},
slice: {
rows: [
{
uniqueName: "Country",
filter: {
exclude: ["Australia"]
}
}
],
columns: [
{
uniqueName: "[Measures]"
}
],
measures: [
{
uniqueName: "Price"
}
]
}
},
reportcomplete: function() {
pivot.off("reportcomplete");
pivotTableReportComplete = true;
createGoogleChart();
}
});
let pivotTableReportComplete = false;
let googleChartsLoaded = false;
google.charts.load("52", {
packages: ["corechart"]
});
google.charts.setOnLoadCallback(onGoogleChartsLoaded);
function onGoogleChartsLoaded() {
googleChartsLoaded = true;
if (pivotTableReportComplete) {
createGoogleChart();
}
}
function createGoogleChart() {
if (googleChartsLoaded) {
pivot.googlecharts.getData({
type: "pie"
},
drawChart,
drawChart
);
}
}
function drawChart(chartConfig) {
let data = google.visualization.arrayToDataTable(chartConfig.data);
let options = {
chartArea: { width: '75%', height: '90%' },
colors: ['#E4B7E5', '#B288C0', '#7E5A9B', '#63458A', '#9A48D0'],
fontSize: 15,
legend: {
position: "left"
},
fontName: "sans-serif",
height: 400
};
let chart = new google.visualization.PieChart(document.getElementById('googlechart-container'));
chart.draw(data, options);
}