如何将垂直轴零点对齐多个垂直轴图表

时间:2011-03-22 10:43:58

标签: flex charts alignment

基于此Adobe多轴图表示例:http://livedocs.adobe.com/flex/3/html/help.html?content=charts_types_12.html

然后我将一些数据值更改为负数,我的轴不再对齐。

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 个答案:

答案 0 :(得分:1)

您可以使用线性轴的最小和最大属性。

修改示例(已编辑):

<?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>

请注意,我将第一个数据系列的verticalAxis移动到了ColumnChart标记。我正在玩原点线放置问题。然后它击中了我,ColumnChart有一个defualt垂直轴,似乎它的最大值和最小值是根据第一系列数据计算的。 “计算的最大值和最小值”未被默认图表垂直轴的最小和最大属性覆盖。这导致错误的原点线放置。

我想在现实世界中你会动态获取数据。在这种情况下,您必须即时计算最小值和最大值。