简体   繁体   中英

Flex ColumnSeries CSS fills not being applied

I'm trying to set the fill colour of the series in a Flex (v4.6) ColumnChart using CSS. I'm currently using setStyle as I've also set the alpha value, but I understand that this is quite resource intensive so I'm thinking of not setting the alpha and just setting the colour using CSS. However, I can't get it to work using a CSS declaration something like:

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

It works fine if I define the following styles:

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

and apply as follows:

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

Can anybody help please?

Thanks. Dan.

Full code example that doesn't work:

<?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>
mx|ColumnSeries 
{
  fills: #FFCC33,#FF0033,#FF3333,#FF6633,#FF9933;
}

try this, it should work

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM