提昇Flex圖表效能
提昇Flex圖表元件 (Charting Components) 的效能,當你遇到圖表元件的繪製速度慢到想殺人的時候,建議你先從資料開始檢查,再看看圖表元件本身。
- 如果可以,移除掉圖表效果,像是陰影
ChartBase.seriesFilters=[]
- 圖表的data-provider別餵太複雜的物件,尤其是很肥大的XML應該盡量避免,真的必要,可以作adapter物件來繪製之。
- 當需要畫出很多條不同的資料線時,不要來一筆資料餵一次series (chartBase.series),能的話,讀完了再一次餵,因為一旦執行
ChartBase.series = your_new_series_list
會逼迫ChartBase重繪*所有的*的視覺元件,包含標籤、矩陣線、圖表線、軸線…等,很恐怖唷!尤其是你的資料又長到個不行時,老闆不開心、自己也難過。
- 作線性圖( Line Chart )時,別輕易地變更線的樣式,尤其”form”, “miter”, “joint”這幾個,你可以看看官方的原始碼,對於這些屬性有非常不同的繪製演算法。用預設值吧,我相信Flex開發團隊已經先最佳化過了。
- Gutter (gutter top, left, right, bottom) 能的話先給預設值,可以省下運算時間
- 小心使用軸線的單位(unit),針對你的資料多寡,給予適當的單位值,如果你的資料有一千年,把單位切成秒數就不是個明智的作法。
以下是本文的英文版:
Enhance Flex Charting Components Performance
- Clear the beautiful shadows or any other filters.
ChartBase.seriesFilters=[] - Optimize your data objects to be rendered. Do not pass a bunch of huge, complex objects to the data-provider.
- While building a line chart, do NOT change the lineStroke attributes such as “miter”, “joint” if not necessary. Flex Data-Visualization components has optimized the drawing performance to default renderers. To change these attributes may bring up a terrible risk.
- You can remove the grid lines.
- Set explicit gutter values while defining a chart base object.
- If you have to render multiple series in a single chart, try to finish loading all data-providers before you assign series list to chart. Calling this method:
ChartBase.series = your_list
will force the chart to remove *ALL* chart elements( label, grid, axis, series items…) and re-create them. It is really time consuming to refresh the chart if re-assign the series objects again and again.
- Set a lower quality of your flash movie( not available for AIR)
- Mind your axis units. Be very careful while showing up a time-based data set. It is very possible to be the key to skew up your chart performance if the unit is set too small. Given an appropriate unit is highly recommended.
Tags: chart, flex, performance
