6 Replies Latest reply on Jun 10, 2008 5:59 PM by

    Flex linechart add/remove lines

      I am curious if anyone knows of any examples of LineCharts (or column charts, or pie charts) where someone adds and removes lines after the app is already loaded. The only way I can currently see doing it is hacking the data provider variable together, but it gets ugly and I have such pretty XML that already feeds right in. It would be really great if someone has seen this done with checkboxes, or if someone can get me pointed in the right direction.
        • 1. Re: Flex linechart add/remove lines
          Don't know if this is still an issue for you, but you can simply add all the LineSeries and set their 'visible' attribute to 'false' - then add a Legen with 'itemClick' set to a method that toggles the visibility of the associated LineSeries. That way your users can click on the items in the Legend to turn the lines on and off.
          1 person found this helpful
          • 2. Re: Flex linechart add/remove lines
            I am looking for something very similar to this?

            Did you manage to do that?

            • 3. Re: Flex linechart add/remove lines
              laurent_pinson Level 1
              you lineSeries are in the LineChart.series property which is an array. So I think you could simply get the array, change it and you may need to refresh your chart.
              1 person found this helpful
              • 4. Re: Flex linechart add/remove lines
                Yes I did figure this out.

                They key to making the data show/vanish is in fact the LineChart.series variable. however the key to making it display correctly is the dataProvider trait of the LineChart itself. What ever data set you set the LineChart.dataprovider to will control the axis, that or you can feel free to set them manually. I like doing it this way as it causes "auto scaling" especially if you choose your longest data set.

                If that doesn't explain it well enough let me know. I will try to go into more detail after my meetings this morning.
                • 5. Re: Flex linechart add/remove lines
                  ajesing Level 1
                  Yes, I would like to have some more insight into this.

                  • 6. Re: Flex linechart add/remove lines
                    Ok, so heres the score in a little more detail. No matter what Adobe tells you the line chart actually requires 2 axis elements (mx:Axis) one horizontal and one vertical. Now it is smart enough to generate the vertical axis element on its own, even if you only give it a series. You will find that if you create a chart and set only the series, then alter them, the scale or Axis in the Y direction will alter for the data, even though the cart is blank. Now the chart is blank because it has no idea what to use for an X-axis. As such you have to create a Horizontal axis item and set it to the name of the data set to be provided. Now even then it will be blank, since it has no idea what data set to use for the X-axis points.

                    All in all what I am saying is you have to assign the chart one of your data sets as the data provider no matter what. The chart needs this in order to correctly draw the Axis and render your chart.