3 Replies Latest reply on Jul 20, 2011 7:00 AM by Karl_Sigiscar_1971

    Using a chart as an item renderer: solution

    Karl_Sigiscar_1971 Level 3

      1- You have a chart to which you added a DataDrawingCanvas or CartesianDataCanvas or PolarDataCanvas instance in the backgroundElements or annotationsElements array


      2- You want to use this chart as an item renderer


      So, you implement the IListItemRenderer interface (in Flex 3) or IItemRenderer interface  (in Flex 4), but there are some display glitches occuring when the chart is renderered as an item renderer.


      The problem is with the DataDrawingCanvas object lifecycle. First, the chart is created. Then the DataDrawingCanvas is created. Then the data is passed to the chart. Then the chart is invalidated and updateDisplayList is called. When updateDisplayList is called, your drawing takes place.


      So, instead of using the chart as an item renderer in a list, what you can do is create a Canvas based MXML component, instantiate your chart in it, override the data setter that will pass along the data for the dataProvider for the series and any data you need for DataDrawingCanvas. Then you dynamically addChild instances of that MXML component to e.g a VBox or a Group, and you add an event listener to it for FlexEvent.CREATION_COMPLETE. In the FlexEvent.CREATION_COMPLETE handler, set the data property to pass the data to your chart.


      TThis way, there are no rendering problems and no display glitches.