views:

903

answers:

2

Has anyone looked at Yahoo's ASTRA? It's fairly nifty, but I had some issues creating a custom label for a pie chart. They have an example for a line chart, which overrides an axis's series's label renderer. My solution was to override the myPieChart.dataTipFunction. For data that looks like:

myPieChart.dataProvider =
  [ { category: "Groceries", cost: 50 },
    { category: "Transportation", cost: 175} ]
myPieChart.dataField = "cost";
myPieChart.categoryField = "category";

I wrote a function like this:

import com.yahoo.astra.fl.charts.series.*
myPieChart.dataTipFunction = 
  function (obj:Object, index:int, series:ISeries):String {
    return obj.category + "\n$" + obj.cost;
  };

There's ceil(2.718281828459045) problems with this:

  1. I'm directly calling the category and cost properties of the data provider. The names are actually configurable when setting up the chart, I'd like to maintain that flexibility.

  2. The default data tip would show the category, the cost (without a dollar sign), and the percentage it makes up in the pie chart. So here, I've lost the percentage. I just have no idea which property of what would hold that. It might be part of the series.

  3. I probably only need to override the dataItemRenderer for the cost part of the series, but I don't know how to access it. The documentation is a little ... lacking there.

Normally I would just look at the default implementation of the dataTipFunction but it's all inside a compiled shm that's part of the components distributed from yahoo.

Can anyone help me complete this overridden function with percentage information and the flexibility mentioned in point 1?

+2  A: 

Okay... so no-one's tried Astra, or people just avoid Flash questions.

After a lot of guess work it turns out I needed to cast the series to a PieSeries and then work with those member functions, as the ISeries was useless on it's own.

myPieChart.dataTipFunction = 
  function (item:Object, index:int, series:ISeries):String {
    var oPieSeries:PieSeries = series as PieSeries;
    return oPieSeries.itemToCategory(item,index) + "\n$" + 
           oPieSeries.itemToData(item) + "\n" + 
           Number(oPieSeries.itemToPercentage(item)).toFixed(2) + "%";
  };
dlamblin
A: 

The Astra components are distributed with the complete source code. Flash CS3 components use compiled shims because otherwise you'd need to manually add the raw source files to your classpath. As a bonus, they also improve compile times because they're already built for you. Look in the "Source" folder in the Astra zip file, and you'll find all the ActionScript classes for the Astra components.

joshtynjala
That's handy and would have saved me time; I didn't actually download this zip. I was trying to answer a designer's question, and looked at http://developer.yahoo.com/flash/astra-flash/charts/examples.html where the pie chart example was just an FLA. I didn't even have flash on my machine.
dlamblin