Flex中如何在LineChart图表中创建一个自定义的LinearAxis函数标签的例子

By Minidxer | November 24, 2008

接下来的例子演示了Flex中Flex中如何在LineChart图表中,创建一个自定义的LinearAxis函数标签。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Script>
  8.         <![CDATA[
  9.             import mx.charts.chartClasses.IAxis;
  10.  
  11.             private function linearAxis_labelFunc(item:Object, prevValue:Object, axis:IAxis):String {
  12.                 return currFormatter.format(item);
  13.             }
  14.         ]]>
  15.     </mx:Script>
  16.  
  17.     <mx:CurrencyFormatter id="currFormatter" precision="2" />
  18.  
  19.     <mx:XMLListCollection id="dp">
  20.         <mx:source>
  21.             <mx:XMLList>
  22.                 <quote date="8/1/2007" open="40.29" close="39.58" />
  23.                 <quote date="8/2/2007" open="39.4" close="39.52" />
  24.                 <quote date="8/3/2007" open="39.47" close="38.75" />
  25.                 <quote date="8/6/2007" open="38.71" close="39.38" />
  26.                 <quote date="8/7/2007" open="39.08" close="39.42" />
  27.                 <quote date="8/8/2007" open="39.61" close="40.23" />
  28.                 <quote date="8/9/2007" open="39.9" close="40.75" />
  29.                 <quote date="8/10/2007" open="41.3" close="41.06" />
  30.                 <quote date="8/13/2007" open="41" close="40.83" />
  31.                 <quote date="8/14/2007" open="41.01" close="40.41" />
  32.                 <quote date="8/15/2007" open="40.22" close="40.18" />
  33.                 <quote date="8/16/2007" open="39.83" close="39.96" />
  34.                 <quote date="8/17/2007" open="40.18" close="40.32" />
  35.                 <quote date="8/20/2007" open="40.55" close="40.74" />
  36.                 <quote date="8/21/2007" open="40.41" close="40.13" />
  37.                 <quote date="8/22/2007" open="40.4" close="40.77" />
  38.                 <quote date="8/23/2007" open="40.82" close="40.6" />
  39.                 <quote date="8/24/2007" open="40.5" close="40.41" />
  40.                 <quote date="8/27/2007" open="40.38" close="40.81" />
  41.             </mx:XMLList>
  42.         </mx:source>
  43.     </mx:XMLListCollection>
  44.  
  45.     <mx:LineChart id="lineChart"
  46.             showDataTips="true"
  47.             dataProvider="{dp}"
  48.             width="100%"
  49.             height="100%">
  50.  
  51.         <!-- vertical axis -->
  52.         <mx:verticalAxis>
  53.             <mx:LinearAxis baseAtZero="false"
  54.                     title="Price"
  55.                     labelFunction="linearAxis_labelFunc" />
  56.         </mx:verticalAxis>
  57.  
  58.         <!-- horizontal axis -->
  59.         <mx:horizontalAxis>
  60.             <mx:CategoryAxis id="ca"
  61.                     categoryField="@date"
  62.                     title="Date" />
  63.         </mx:horizontalAxis>
  64.  
  65.         <!-- horizontal axis renderer -->
  66.         <mx:horizontalAxisRenderers>
  67.             <mx:AxisRenderer axis="{ca}"
  68.                     canDropLabels="true" />
  69.         </mx:horizontalAxisRenderers>
  70.  
  71.         <!-- series -->
  72.         <mx:series>
  73.             <mx:LineSeries yField="@open"
  74.                     form="curve"
  75.                     displayName="Open" />
  76.         </mx:series>
  77.  
  78.         <!-- series filters -->
  79.         <mx:seriesFilters>
  80.             <mx:Array />
  81.         </mx:seriesFilters>
  82.     </mx:LineChart>
  83.  
  84. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Chart | No Comments » | Tags: , , ,

Search Posts