Sep
30
2010

Dynamically change Flex chart types

Generally, we can replace the existing Flex object chart with new one to dynamically change Flex Chart types, but it is very boring. Here We recommand a better way: using getDefinitionByName() method.

View the demo, download the source code.

This following example is only talked about CartesianChart, so changing the chart type can be equal to change the series type.Therefore, we can expand the the cartesian series, then use getDefinitionByName() method dynamically instruct series object, the core code is in the set accessor of seriesType.

public function set seriesType(value:String):void
{
	_seriesType = value;
	var seriesArr:Array = this.series;
	var ClassReference:Class = getDefinitionByName("components.chart.series." + _seriesType) as Class;
	var s:Series = new ClassReference();
	seriesArr[0] = s;
	this.series = seriesArr;
}

In addition, we also add an inspectable metadata tags (seriesType) as shown below:

[Inspectable(category="General", enumeration="Line,Mountain,Candlestick,HLOC", defaultValue="Mountain")]

The [Inspectable] metadata tag can indicate the default value of the property for Flash Builder.

原文:http://www.riafan.com/article/flex/change-flex-chart-type.html

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading