【问题标题】:Using Per Item Fills in Flex/Actionscript在 Flex/Actionscript 中使用每个项目填充
【发布时间】:2009-11-03 10:34:33
【问题描述】:

我正在使用 mxml 创建图表。 mxml 标签只创建一个有横轴和纵轴的图表。

我的结果事件处理程序具有遍历 xml 结果集并创建所有系列(线系列和堆叠条)的 actionscript 代码。这部分代码运行良好。

现在我需要使用 functionfill 函数为每个系列设置单独的颜色。我发现的所有示例都从 MXML 标记中调用函数填充,如下所示:

       <mx:ColumnSeries id="salesGoalSeries" 
            xField="Name" 
            yField="SalesGoal" 
            fillFunction="myFillFunction" 
            displayName="Sales Goal">

我在从 actionscript 调用函数填充时遇到问题。

构建数据系列的部分代码如下:

if (node.attribute("ConfidenceStatus")=="Backlog" 
|| node.attribute("ConfidenceStatus")=="Billings") {
// Create the new column series and set its properties.
var localSeries:ColumnSeries = new ColumnSeries();
localSeries.dataProvider = dataArray;
localSeries.yField = node.attribute("ConfidenceStatus");
localSeries.xField = "TimebyDay";
localSeries.displayName = node.attribute("ConfidenceStatus");
localSeries.setStyle("showDataEffect", ChangeEffect);
localSeries.fillFunction(setSeriesColor(xxx));

// Back up the current series on the chart.
var currentSeries:Array = chart.series;

// Add the new series to the current Array of series.
currentSeries.push(localSeries);

//Add Array of series to columnset
colSet.series.push(localSeries);  

//assign columnset to chart
chart.series = [colSet];

我的 setSeriesColor 函数是:

private function setSeriesColor(element:ChartItem, index:Number):IFill {
var c:SolidColor = new SolidColor(0x00CC00);
var item:ColumnSeriesItem = ColumnSeriesItem(element);

//will put in logic here
return c;

}

我在 localSeries.fillFunction(setSeriesColor(xxx)) 行中放了哪些参数?

我尝试将 localSeries 作为第一个参数,但我得到一个隐含的强制错误,告诉我 localSeries 不能转换为 ChartItem。

如何正确调用函数?

【问题讨论】:

    标签: apache-flex actionscript charts


    【解决方案1】:
    localSeries.fillFunction = setSeriesColor;
    

    您现在拥有的代码实际上是按照您设置它的方式调用 setSeriesColor。您只希望它引用函数的引用,而不是调用它,所以只需将它作为变量发送“setSeriesColor”。

    【讨论】:

    • 是的!函数是 AS3 中的对象。
    • 好的,这是有道理的,也很方便。 Flex 自动传递正确的参数。你怎么知道什么时候调用一个函数,什么时候引用一个函数的引用?
    • 我通常只是想,“调用函数是谁的责任?”。如果是我的责任,我会自己调用它,否则它会作为变量传递,我会让其他人调用它。这是 AS3 中非常常见的做法。事件处理程序是以这种方式编写的,因此您可以练习一些以了解这个想法。在文档中,函数变量通常是指接口(IFill 表示 fillFunction),因此也可以作为指标。
    猜你喜欢
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    相关资源
    最近更新 更多