--- In [email protected], john fisher <[EMAIL PROTECTED]> wrote:
>
> I must be doing something simple wrong here.....
> 
> What I am doing:
> creating a column chart entirely in AS, and controlling the colors, 
and
> series, and legend in AS. The legend will be in a grid, instead of
> automatic in the chart.
> once the XML data is acquired, the makeserviceschart assembles the
> chart, including choosing which data to include, and which colors to
> use, and then finally calls  drawlegend, passing the grid and chart
> objects, in order to assemble the legend in a Grid.
> 
> What doesn't work:
> The legend gets the data name ( label) correct, but doesn't get the 
fill
> color.
> Back inside the makeserviceschart, I can't trace out the fill color
> using getStyle either, even though I have just set it using 
setStyle.
> The getStyle syntax is a cut&paste from the Adobe example code app:
> 
http://blogs.adobe.com/flexdoc/2008/07/customized_legend_layout.html  
> which DOES work on my system....
> 
> // SMALL SNIPPET
> 
> // set the color from the colorlist array of SolidColors
> series1.setStyle("fill", colorlist[count]) ; //THIS WORKS CORRECTLY
> 
> // in the legend building func
> // Apply the current series' displayName to the LegendItem's label.
>                         li.label = colChart.series[z].displayName;
>                                     display( li.label ) ;  // YEP 
THIS WORKS
>                                     display( 
colChart.series.length) ;
> // YEP THIS WORKS
>                         // Get the current series' fill.
>                         var sc:SolidColor =
> colChart.series[z].getStyle("fill"); // NOPE NO COLORS SHOW UP
>                                 display("color sc = " +  sc ); // 
NOPE
> TRACES "NULL"
>                                 display("series color fill = " +
> colChart.series[z].getStyle("fill")  ); //NOPE TRACES "UNDEFINED"
>                       // I tried toString()  and toString(16)  and 
sc.color
> 
> 
> // BIG CODE SNIPPET
> 
> //THE CHART FUNCTION     
>          public function makeserviceschart():void {
>             var myChart:ColumnChart;
>               var series1:ColumnSeries ;
>               var mySeries:Array=new Array();
>               var data_items:Array = new
> Array("inpkts",..."inbytes","outbytes"); // dummy user-selected 
data choices
>            
> // THE DATA
>              simpleServicesData = new ArrayCollection([]); //subset 
of
> the XML
>              // various data munging ops snipped out here
> 
>             myChart  = new ColumnChart();
>             myChart.showDataTips = true;
>             myChart.dataProvider = simpleServicesData;
> 
>             // Define the category axis.
>             var hAxis:CategoryAxis = new CategoryAxis();
>             hAxis.categoryField = "name" ;
>             hAxis.dataProvider =  simpleServicesData;
>             myChart.horizontalAxis = hAxis;
>            
>             // define the vertical axis
>             var vAxis:LogAxis = new LogAxis();  // makes logarithmic
>             vAxis.interval = 10 ;
>             myChart.verticalAxis = vAxis;
>      
>             //create the colors
>             var colorlist:Array =     new Array(
>                 new SolidColor(0x8dd3c7, .8),    ....,     );
> 
>             // Add the series:
>                var count:int = 0 ;
>             for each (var item:String in data_items){               
>                 series1 = new ColumnSeries();
>                 series1.xField="name";
>                 series1.yField= item ;
>                 series1.displayName = item;
>                 series1.setStyle("fill", colorlist[count]) ; //THIS
> WORKS CORRECTLY
>                 mySeries.push(series1);               
>                 count++ ;
>             }           
>             // add all the series to the chart
>             myChart.series = mySeries;
> 
>              // Attach chart and legend to the display list.
>             // first kill off the previous version of the chart
>               serviceschart.removeAllChildren();
>             serviceschart.addChild(myChart);
> 
>             //Create a dynamically sized grid for numerous legend
> items        
>             drawlegend(myChart, serviceslegend) ;
>         
>      }
> //THE LEGEND TO GRID FUNC called by makeserviceschart
>         // taken from here:
> 
http://blogs.adobe.com/flexdoc/2008/07/customized_legend_layout.html 
>         private function drawlegend(colChart:ColumnChart,
> myGrid:Grid):void {
>             // empty grid object
>             myGrid.removeAllChildren();
>         
>         //SNIPPED OUT  SETUP OF VARS
>             for (var j:int = 0; j < numRows; j++) {
>                 var gr:GridRow = new GridRow();
>                 myGrid.addChild(gr);
>            
>                 for (var k:int = 0; k < rowSize; k++) {
>                     // As long as the series counter is less than 
the
> number of series...
>                     if (z < colChart.series.length) {
>                         var gi:GridItem = new GridItem();
>                         gr.addChild(gi);
>                        
>                         var li:LegendItem = new LegendItem();
>                        
>                         // Apply the current series' displayName to 
the
> LegendItem's label.
>                         li.label = colChart.series[z].displayName;
>                                     display("li lable = " + 
li.label )
> ;  // YEP THIS WORKS
>                                     display("chart series length 
= " +
> colChart.series.length) ; // YEP THIS WORKS
>                         // Get the current series' fill.
>                         var sc:SolidColor =
> colChart.series[z].getStyle("fill"); // NOPE NO COLORS SHOW UP
>                                 display("color sc = " +  sc ); // 

If it were me, I'd put the result of the getStyle() into a variable 
with a * type and set a break point to look at it in the variables 
window, rather than trying to trace it out.

I have an extended Legend that wraps the way it's supposed to, if 
you'd like that.  The problem with Legend control is that the 
LegendItems can't wrap their text to respect the width they're given 
by the control, and the Leged apparently can't resolve the difference 
between the width it thought it was giving the items and the width 
they actually wind up with, so it doesn't know it should start a new 
row.

Contact me at amy at magnoliamultimedia dot com if you'd like the 
extended Legend.

HTH;

Amy

Reply via email to