2011-03-22 122 views
0

http://livedocs.adobe.com/flex/3/html/help.html?content=charts_types_12.html如何對齊垂直軸零在此基礎上的Adobe多軸圖表例如多個垂直軸圖表

然後,我改變了一些數據值來負,我成了軸不再一致。

enter image description here

有誰知道如何使垂直軸?這是另一個Adobe bug還是有一些對齊軸的屬性?謝謝

<?xml version="1.0" encoding="utf-8"?> 
<s:Application 
    minHeight="600" 
    minWidth="955" 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 

      [Bindable] public var SMITH:ArrayCollection = new ArrayCollection([{date:"22-Aug-05", close:41.87}, 
                       {date:"23-Aug-05", close:-45.74}, 
                       {date:"24-Aug-05", close:-42.77}, 
                       {date:"25-Aug-05", close:48.06},]); 

      [Bindable] public var DECKER:ArrayCollection = new ArrayCollection([{date:"22-Aug-05", close:157.59}, 
                       {date:"23-Aug-05", close:-160.3}, 
                       {date:"24-Aug-05", close:-150.71}, 
                       {date:"25-Aug-05", close:156.88},]); 
     ]]> 
    </fx:Script> 

    <mx:Panel title="Column Chart With Multiple Axes"> 
     <mx:ColumnChart id="myChart" 
      showDataTips="true" 
      type="overlaid"> 
      <mx:horizontalAxis> 
       <mx:CategoryAxis id="h1" 
        categoryField="date"/> 
      </mx:horizontalAxis> 

      <mx:horizontalAxisRenderers> 
       <mx:AxisRenderer placement="bottom" 
        axis="{h1}"/> 
      </mx:horizontalAxisRenderers> 

      <mx:verticalAxisRenderers> 
       <mx:AxisRenderer placement="left" 
        axis="{v1}"/> 
       <mx:AxisRenderer placement="left" 
        axis="{v2}"/> 
      </mx:verticalAxisRenderers> 

      <mx:series> 
       <mx:ColumnSeries id="cs1" 
        dataProvider="{SMITH}" 
        horizontalAxis="{h1}" 
        yField="close" 
        displayName="SMITH"> 
        <mx:verticalAxis> 
         <mx:LinearAxis id="v1"/> 
        </mx:verticalAxis> 
       </mx:ColumnSeries> 
       <mx:LineSeries id="cs2" 
        dataProvider="{DECKER}" 
        horizontalAxis="{h1}" 
        yField="close" 
        displayName="DECKER"> 
        <mx:verticalAxis> 
         <mx:LinearAxis id="v2"/> 
        </mx:verticalAxis> 
       </mx:LineSeries> 
      </mx:series> 
     </mx:ColumnChart> 
     <mx:Legend dataProvider="{myChart}"/> 
    </mx:Panel> 
</s:Application> 

回答

1

您可以使用Linear軸的最小和最大屬性。

變形例(編輯):

<?xml version="1.0" encoding="utf-8"?> 
<s:Application 
    minHeight="600" 
    minWidth="955" 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 

      [Bindable] public var SMITH:ArrayCollection = new ArrayCollection([{date:"22-Aug-05", close:41.87}, 
       {date:"23-Aug-05", close:-45.74}, 
       {date:"24-Aug-05", close:-42.77}, 
       {date:"25-Aug-05", close:48.06},]); 

      [Bindable] public var DECKER:ArrayCollection = new ArrayCollection([{date:"22-Aug-05", close:157.59}, 
       {date:"23-Aug-05", close:-160.3}, 
       {date:"24-Aug-05", close:-150.71}, 
       {date:"25-Aug-05", close:156.88},]); 
     ]]> 
    </fx:Script> 

    <mx:Panel title="Column Chart With Multiple Axes"> 
     <mx:ColumnChart id="myChart" 
         showDataTips="true" 
         type="overlaid" 
         > 

      <mx:horizontalAxis> 
       <mx:CategoryAxis id="h1" 
           categoryField="date"/> 
      </mx:horizontalAxis> 

      <mx:horizontalAxisRenderers> 
       <mx:AxisRenderer placement="bottom" 
           axis="{h1}"/> 
      </mx:horizontalAxisRenderers> 

      <mx:verticalAxis> 
       <mx:LinearAxis id="v1" minimum="-50" maximum="50" autoAdjust="false"/> 
      </mx:verticalAxis>   

      <mx:verticalAxisRenderers> 
       <mx:AxisRenderer placement="left" 
           axis="{v1}"/> 
       <mx:AxisRenderer placement="left" 
           axis="{v2}"/> 
      </mx:verticalAxisRenderers> 

      <mx:series> 
       <mx:ColumnSeries id="cs1" 
           dataProvider="{SMITH}" 
           horizontalAxis="{h1}" 
           yField="close" 
           displayName="SMITH" 
           > 
       </mx:ColumnSeries> 
       <mx:LineSeries id="cs2" 
           dataProvider="{DECKER}" 
           horizontalAxis="{h1}" 
           yField="close" 
           displayName="DECKER" 
           > 
        <mx:verticalAxis > 
         <mx:LinearAxis id="v2" minimum="-180" maximum="180" autoAdjust="false"/> 
        </mx:verticalAxis> 
       </mx:LineSeries> 
      </mx:series> 
     </mx:ColumnChart> 
     <mx:Legend dataProvider="{myChart}"/> 
    </mx:Panel> 
</s:Application> 

。注意,我立軸移動對第一系列數據來將ColumnChart標籤。我正在玩弄原始線放置問題。然後它激怒了我,ColumnChart忽略了垂直軸,看起來,它的最大值和最小值是根據第一組數據計算出來的。計算最大值和最小值未被默認圖表垂直軸的最小和最大屬性覆蓋。這導致錯誤的原點線位置。

我想在現實世界中,你會動態獲取數據。在這種情況下,您必須即時計算最小值和最大值。

+0

謝謝,這部分解決了這個問題。但是由於某種原因,存在黑暗的水平線...... – zinovii 2011-03-22 12:07:38

+0

請更具體一點,你的意思是什麼黑線? – 2011-03-23 06:23:45

+0

我想我知道「黑色水平線」是什麼。它似乎是圖表的起源線。它確實被置於錯誤的位置。在玩過這個問題之後,我修改了一個例子。 – 2011-03-23 09:08:48