pieChart purely in Actionscipt
Similar to last week, I gave the raw basis of a LineChart, this week I’ll post on how to render a pieChart, slightly different… here goes, same dataProvider
private function getDataProvider():ArrayCollection {
var arr:Array = [];
arr.push({title: “Benefit 1″, data: 2});
arr.push({title: “Benefit 2″, data: 5});
arr.push({title: “Benefit 3″, data: 6});
arr.push({title: “Benefit 4″, data: 3});
return new ArrayCollection(arr);
}
the pieChart is the following:
private function drawPieChart():void {
var dummyData:ArrayCollection;
dummyData = getDataProvider();
var series:PieSeries;
series = new PieSeries();
series.nameField = "title";
series.field = "data";
series.filters = [];
pieChart = new PieChart();
pieChart.percentWidth = 60;
pieChart.percentHeight = 60;
pieChart.showDataTips = true;
pieChart.dataProvider = dummyData;
pieChart.series = [series];
pieChart.y = 75;
pieChart.x = 70;
var legendPie = new Legend(); // add a legend to your chart
legendPie.dataProvider = pieChart;
legendPie.x = 516;
legendPie.y = 134;
chartContainer.addChild(pieChart);
chartContainer.addChild(legendPie);
}
The ‘chartContainer’ is the id of a container say of, a canvas or any other sort of container you wish. Enjoy.