4 Replies Latest reply on Jun 12, 2007 4:58 PM by jason_v2

    Creating charts in actionscript


      Im working on producing charts that can have a dynamic number of data series. Seems the best way to do this is to produce the charts in actionscript. I have it working so the chart displays as wanted. but can't find a way to apply my mxml gradient fills and effects in actionscript ....

      ie, this produced nice blue bars for my columns ....

      <mx:ColumnSeries yField="value" showDataEffect="{interpolate}">
      <mx:GradientEntry color="#C6D5DD" ratio="0" alpha="100"/>
      <mx:GradientEntry color="#336699" ratio="0.05" alpha="100"/>
      <mx:GradientEntry color="#24496D" ratio="0.95" alpha="100"/>
      <mx:GradientEntry color="#000000" ratio="1" alpha="100"/>

      in actionscript i can produce the ColumnSeries and the LinearGradients / GradientEntry, but can't see a way to connect the two.

      var colSeries:ColumnSeries = new ColumnSeries();
      colSeries.yField = "value";

      var linearGradient:LinearGradient = new LinearGradient();
      var gradientEntry:GradientEntry = new GradientEntry();

      var cG1 = new GradientEntry(0xC6D5DD,0,1);
      var cG2 = new GradientEntry(0x336699,0.05,1);
      var cG3 = new GradientEntry(0x24496D,0.95,1);
      var cG4 = new GradientEntry(0x000000,1,1);

      linearGradient.entries = [cG1, cG2, cG3, cG4];

      But how do i tell the ColumnSeries to use the LinearGradient in actionsctript?

      Also when trying to use the ColumnSeries.showDataEffect im greeted with "Error: Access of possibly undefined property showDataEffect through a reference with static type mx.charts.series:ColumnSeries" ... how can i set chart effects in actionscript?

      Any help would be greatly appreciated

        • 1. Creating charts in actionscript
          McDusty Level 1
          Rather embarrassingly i found the answer to one of my problems within 5 mins of asking this ... one can tell the ColumnSeries to use the LinearGradient with the setStyle funtion ...


          However im still stuck on how to get my showDataEffect working in actionscript.
          • 2. Re: Creating charts in actionscript
            bolaughlin Level 1
            use setStyle for the effect as well. Assuming an effect you defined named "myInterpolate":

            colSeries.setStyle ("showDataEffect", myInterpolate);

            • 3. Re: Creating charts in actionscript
              McDusty Level 1
              Cheers Brian, that worked.

              Don't know why i didn't think of that. Was trying to attach an event listener to 'showData', and create my own seriesInterpolate, but to no avail.

              • 4. Re: Creating charts in actionscript
                Hey guys,

                I tried the same kinda thing but with no success. I have a pie chart where I want to specify a gradient fill for each individual slice (kind of like the Flex Dashboard example), except, I want to do it in Actionscript.

                var pieChart:PieChart = new PieChart;
                var series:PieSeries = new PieSeries;

                /*A bunch of other stuff goes here styling/binding/etc*/

                var grad1:GradientEntry = new GradientEntry(0xC6D5DD,0.3);
                var grad2:GradientEntry = new GradientEntry(0x336699,0.3);
                var grad3:GradientEntry = new GradientEntry(0x24496D,0.3);
                var grad4:GradientEntry = new GradientEntry(0x000000,0.3);

                radialGradient.entries = [grad1,grad2,grad3,grad4];

                series.setStyle("fill", radialGradient);


                Can anyone see anything blatantly wrong with this? Thanks!!