Apr
12
2011

Completely hide series in a Flex chart

Generally, if there are already more Series in a chart, we usually don't directly remove the Series. We would hide  them and show them again when needed rather than directly re-request data to redraw the chart. You may say, that's easy, just set the Series visible property to false, right? It's not true, the Series have been hidden, but their axes haven’t been updated.

http://flexdevtips.blogspot.com/2009/10/linechart-with-checkbox-legend.html, in this article the author gives a solution: compare each Series Item values among all Series Items, calculate the maximum and minimum values and assign them to their axes maximum and minimum properties. This solution is good, but lack of the implementation efficiency. By the way, if there are many axes need updating, it's difficult to handle this problem by this way. Here I find another way.

That’s to say, hide chart Series when they are removed from the chart series array as an element in the memory, display chart Series when they are added the chart series array.

View the demo, Download the source code.

Notes:

1. The chart legend is customized by using an DataGroup container. By default, if you click on the gap space between the legend mark and the legend label, the LegendMouseEvent can't be triggered.

2. The code that hides and displays the chart Series is written in the ItemRenderer. I think this is more convenient, but the best practice is dispatching the event from the ItemRenderer to decouple the views and controls.

3. After remove a chat Series from its series array, we should re-index the left Series in the chart. When the chat Series is displayed, we should add the hidden Series at new position that equals to the current Series index in the last series array.

原文:http://www.riafan.com/article/flex/completely-hide-series-in-flex-chart.html

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Month List