【问题标题】:Flex Chart : Change style for positive and negative valuesFlex Chart : 改变正负值的样式
【发布时间】:2010-11-08 07:45:24
【问题描述】:

有没有办法根据值更改 Flex Chart 的样式。 比如在柱形图中,设置绿色为正值,红色为负值?

【问题讨论】:

  • 十个问题,没有一个被接受的答案。不酷。

标签: apache-flex coding-style charts


【解决方案1】:

需要为您的 ColumnSeries 提供一个 fillFunction 属性,该属性用于根据给定列的值计算 IFill。比如:

<?xml version="1.0"?>
<!-- Simple example to demonstrate the ColumnChart and BarChart controls. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            import mx.charts.ChartItem;
            import mx.graphics.IFill;          
            import mx.collections.ArrayCollection;

            private function fillFunction (item:ChartItem, index:Number):IFill
            {  
                if(item.item.Gold > 0)
                {
                    return new SolidColor(0x00FF00);
                } else {
                    return new SolidColor(0xFF0000);
                }
            }


            [Bindable]
            private var medalsAC:ArrayCollection = new ArrayCollection( [
                { Country: "USA", Gold: 35},
                { Country: "China", Gold: -5},
                { Country: "Russia", Gold: 27} ]);
        ]]>
    </mx:Script>

    <!-- Define custom colors for use as fills. -->
    <mx:SolidColor id="sc1" color="yellow" alpha=".8"/>

    <!-- Define custom Strokes for the columns. -->
    <mx:Stroke id="s1" color="yellow" weight="2"/>

    <mx:Panel title="ColumnChart and BarChart Controls Example" 
        height="100%" width="100%" layout="horizontal">
        <mx:ColumnChart id="column" 
            height="100%" 
            width="100%" 
            paddingLeft="5" 
            paddingRight="5" 
            showDataTips="true" 
            dataProvider="{medalsAC}"
        >                
            <mx:horizontalAxis>
                <mx:CategoryAxis categoryField="Country"/>
            </mx:horizontalAxis>

            <mx:series>
                <mx:ColumnSeries 
                    xField="Country" 
                    yField="Gold" 
                    displayName="Gold"
                    fill="{sc1}"
                    stroke="{s1}"
                    fillFunction="{fillFunction}"
                />
            </mx:series>
        </mx:ColumnChart>

        <mx:Legend dataProvider="{column}"/>

    </mx:Panel>
</mx:Application>

【讨论】:

    猜你喜欢
    • 2011-04-06
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 2020-12-11
    相关资源
    最近更新 更多