4 Replies Latest reply on Jun 24, 2011 3:40 AM by Simhanature

    Can I access Flex's default Chart colors? Or can I access a Series' current color?

    inghamc Level 1

      I've created a popup to dynamically add/remove Series from a LineChart and/or AreaChart.  Problem is, I want to keep the Series' line color consistent, and Flex wants to re-assign them from it's default list, which is confusing.

       

      I don't want to just set the Series.visible to false for two reasons:

       

      1. I also want the LegendItem to disappear from the Legend

       

      2. Stacked AreaCharts (type == 'stacked') get messed up when you set one of its Series.visible = false

       

      So to avoid color reassignment, I want to explicitly set the lineStroke for my Series.  But if I'm using Flex's default colors, I need to either:

       

      a. Have access to the static default color array - does anyone know where this is???  or

       

      b. After the Series are drawn (updateComplete?), I need to query each for its lineStroke color and then explicitly set it to that same color.  How do I do this???  getStyle('lineStroke') returns null, and I can't see a way to get at the renderer.

       

       

      I'm essentially re-posting the following unanswered posts, which I promise to link back to this if someone can please help:

       

      Binding to Rendered Chart Data [http://forums.adobe.com/message/186840#186840]


      Getting the default pie chart colors [http://forums.adobe.com/message/36410#36410]

       

      Please help!

        • 1. Re: Can I access Flex's default Chart colors? Or can I access a Series' current color?
          matthew horn Level 3

          The colors are defined on the series. For a single-color series, like BarSeries or LineSeries, you want to get the fill:

           

                      var o:Object = myBarSeries.getStyle("fill");
                      l1.text = o.color;

           

          For a multi-color series, like PieSeries, you want to get the fills:

           

                          var a:Array = myPieSeries.getStyle("fills");
                          for (var i:int = 0; i<a.length; i++) {
                              ta1.text += a[i] + "\n";

                         }

           

          I apologize, but I don't have the cycles to check how the colors are stored in stacked charts, but maybe this will help.

           

          hth,

          matt horn

          flex docs

          • 2. Re: Can I access Flex's default Chart colors? Or can I access a Series' current color?
            inghamc Level 1

            Matt, thanks for your reply, but unfortunately, for LineCharts, LineSeries.getStyle('fill') always returns 0xffffff (white).

             

            I finally found that after my LineChart is completely rendered, (sometime after LineSeries' updateComplete), LineSeries.getStyle('lineStroke') and getStyle('stroke') both return the correct Stroke.color values ("lineStroke" refers to the line segment and "stroke" to the data point).

             

            Rather than fooling around with collecting the actual values dynamically, I just generated some trace() output from a  LineChart with a bunch of Series to create my own static Array from which I can initialize my Series.setStyle(color) as I dynamically add them to my LineChart:


                    public static const DEFAULT_FLEX_SERIES_COLORS:Array = [
                        0xe48701, 0xa5bc4e, 0x1b95d9, 0xcaca9e,
                        0x6693b0, 0xf05e27, 0x86d1e4, 0xe4f9a0,
                        0xffd512, 0x75b000, 0x0662b0, 0xede8c6,
                        0xcc3300, 0xd1dfe7, 0x52d4ca, 0xc5e05d,
                        0xe7c174, 0xfff797, 0xc5f68f, 0xbdf1e6,
                        0x9e987d, 0xeb988d, 0x91c9e5, 0x93dc4a,
                        0xffb900, 0x9ebbcd, 0x009797, 0x0db2c2
                    ];

             

            It turns out there's only 28 unique color values before the color pattern repeats.  I don't see a numerical pattern; perhaps someone with more time on their hands can figure out if there's a function behind this series of values (printed here in binary, decimal, and hex):

             

                    111001001000011100000001  14976769  0xe48701
                    101001011011110001001110  10861646  0xa5bc4e
                    000110111001010111011001  01807833  0x1b95d9
                    110010101100101010011110  13290142  0xcaca9e
                    011001101001001110110000  06722480  0x6693b0
                    111100000101111000100111  15752743  0xf05e27
                    100001101101000111100100  08835556  0x86d1e4
                    111001001111100110100000  15006112  0xe4f9a0
                    111111111101010100010010  16766226  0xffd512
                    011101011011000000000000  07712768  0x75b000
                    000001100110001010110000  00418480  0x0662b0
                    111011011110100011000110  15591622  0xede8c6
                    110011000011001100000000  13382400  0xcc3300
                    110100011101111111100111  13754343  0xd1dfe7
                    010100101101010011001010  05428426  0x52d4ca
                    110001011110000001011101  12968029  0xc5e05d
                    111001111100000101110100  15188340  0xe7c174
                    111111111111011110010111  16775063  0xfff797
                    110001011111011010001111  12973711  0xc5f68f
                    101111011111000111100110  12448230  0xbdf1e6
                    100111101001100001111101  10393725  0x9e987d
                    111010111001100010001101  15440013  0xeb988d
                    100100011100100111100101  09554405  0x91c9e5
                    100100111101110001001010  09690186  0x93dc4a
                    111111111011100100000000  16759040  0xffb900
                    100111101011101111001101  10402765  0x9ebbcd
                    000000001001011110010111  00038807  0x009797
                    000011011011001011000010  00897730  0x0db2c2

             

            Anyway, it sure would have been nice to have access to this in the API - hopefully I've saved someone else the time I've wasted...

            • 3. Re: Can I access Flex's default Chart colors? Or can I access a Series' current color?
              Simhanature

              Thanks inghamc & matt horn. This is what I am looking for. This one really saved my time..

              • 4. Re: Can I access Flex's default Chart colors? Or can I access a Series' current color?
                Simhanature Level 1

                Hi guys,

                 

                I have found that we can access default chart colors from a Base Class they use to fill the chart and we can alter it if we need. You might know this already, I just want to post it because someone who need it can save their time.

                 

                It is declared as mx_internal variable in the class HaloDefaults.as as an array in the name "defaultColors".

                You can access and alter with your own set of values if you need.

                Here is the code you need.

                 

                 

                import mx.charts.styles.HaloDefaults;

                 

                HaloDefaults.mx_internal::defaultColors =

                [

                0x6693B0

                ,0xF05E27

                ,0x86D1E4

                ,0xE4F9A0

                                                       ...

                                                        ...

                                                        ,0xEB988D

                                                        ]

                This array should be of length 28.

                 

                # "Need to use mx_internal with their own risk as these variables may not be available in future versions", as adobe says always.