Skip to content

pieChart purely in Actionscipt

June 19, 2008

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.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: