Flex ColumnSeries CSS填充未应用

时间:2011-12-30 08:42:35

标签: css flash flex

我正在尝试使用CSS在Flex(v4.6)ColumnChart中设置系列的填充颜色。我目前正在使用setStyle,因为我还设置了alpha值,但我知道这是非常耗费资源的,所以我想不设置alpha并只使用CSS设置颜色。但是,我无法使用CSS声明来实现:

mx|ColumnSeries {
fills: #FFCC33, #FF0033, #FF3333, #FF6633, #FF9933;

如果我定义以下样式,它可以正常工作:

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";

        .anotherColour { fill: #CCFFB3; }

        .andAnotherColour { fill: #BBFF99; }

    </fx:Style>

并按如下方式申请:

                <mx:ColumnSeries 
                    xField="Month" 
                    yField="Profit" 
                    displayName="Profit"
                    styleName="anotherColour"
                    />
                <mx:ColumnSeries 
                    xField="Month" 
                    yField="Expenses" 
                    displayName="Expenses"
                    styleName="andAnotherColour"
                    />

有人可以帮忙吗?

感谢。丹。

不起作用的完整代码示例:

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

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";

        mx|ColumnSeries {
            fills: #CCFFB3, #BBFF99;

        }
    </fx:Style>


    <fx:Script>
        <![CDATA[
        import mx.collections.ArrayCollection;
        [Bindable]
        public var expenses:ArrayCollection = new ArrayCollection([
        {Month:"Jan", Profit:2000, Expenses:1500},
        {Month:"Feb", Profit:1000, Expenses:200},
        {Month:"Mar", Profit:1500, Expenses:500}
        ]);]]>
    </fx:Script>
    <mx:Panel title="Column Chart">
        <mx:ColumnChart id="myChart" dataProvider="{expenses}" showDataTips="true">
            <mx:horizontalAxis>
                <mx:CategoryAxis 
                    dataProvider="{expenses}" 
                    categoryField="Month"
                    />
            </mx:horizontalAxis>
            <mx:series>
                <mx:ColumnSeries 
                    xField="Month" 
                    yField="Profit" 
                    displayName="Profit"
                    />
                <mx:ColumnSeries 
                    xField="Month" 
                    yField="Expenses" 
                    displayName="Expenses"
                    />
            </mx:series>
        </mx:ColumnChart>
        <mx:Legend dataProvider="{myChart}"/>
    </mx:Panel>
</s:Application>

2 个答案:

答案 0 :(得分:0)

试试这个:

 mx|ColumnSeries {
                fills: [0xFFCC33,0xFF0033,0xFF3333,0xFF6633,0xFF9933];
            }

答案 1 :(得分:0)

mx|ColumnSeries 
{
  fills: #FFCC33,#FF0033,#FF3333,#FF6633,#FF9933;
}

试试这个,它应该有用