【问题标题】:When to render Legend in Flex何时在 Flex 中渲染 Legend
【发布时间】:2009-11-11 18:19:35
【问题描述】:

我的 Flex 图表具有从每个数据系列创建图例的代码。目前,我在单击按钮时执行 drawLegend 函数。

我试图让图例自动绘制,但我无法确定何时调用 drawLegend 函数。用户单击检索数据的“更新”按钮。我希望在此之后创建图例,而无需用户单击另一个按钮。

我已将 drawLegend 函数放在几个地方(ResultHandler、afterEffectEnd(用于图表动画等),但没有任何效果。

在将系列添加到图表后以及系列动画结束后的某个时间,可以添加图例。

我怎样才能捕获这个时间点并调用我的函数?

有什么想法吗?

下面是我用来创建图例的代码。请注意,即使代码处理了每个系列,我注意到如果过早调用填充颜色,则填充颜色为空。

private function drawLegend(event:Event):void {
clearLegend();

// Use a counter for the series.
var z:int = 0;

var numRows:int; 
if (chart.series.length % rowSize == 0) {
    // The number of series is exactly divisible by the rowSize.            
    numRows = Math.floor(chart.series.length / rowSize);                
} else {
    // One extra row is needed if there is a remainder.
    numRows = Math.floor(chart.series.length / rowSize) + 1;
}

for (var j:int = 0; j < numRows; j++) {
    var gr:GridRow = new GridRow();
    myGrid.addChild(gr);

    for (var k:int = 0; k < rowSize; k++) {
        // As long as the series counter is less than the number of series...

        //skip columnset group
        if (chart.series[z] is LineSeries || chart.series[z] is ColumnSeries){
            if (z < chart.series.length) {
                var gi:GridItem = new GridItem();
                gr.addChild(gi);

                var li:LegendItem = new LegendItem();

                    // Apply the current series' displayName to the LegendItem's label.
                    li.label = chart.series[z].displayName;

                    // Get the current series' fill.
                    var sc:SolidColor = new SolidColor();
                    sc.color = chart.series[z].items[0].fill.color;

                    // Apply the current series' fill to the corresponding LegendItem.
                    li.setStyle("fill", sc.color);//was just sc

                    // Apply other styles to make the LegendItems look uniform.
                    li.setStyle("textIndent", 5);
                    li.setStyle("labelPlacement", "left");
                    li.setStyle("fontSize", 9);

                    gi.setStyle("backgroundAlpha", "1");
                    gi.setStyle("backgroundColor", sc.color);
                    //gi.width = 80;

                    // Add the LegendItem to the GridItem.
                    gi.addChild(li);
                }
            }
        // Increment any time a LegendItem is added.
        z++;
    }
}                                       

}

【问题讨论】:

    标签: apache-flex actionscript-3 charts


    【解决方案1】:

    好吧,我不太清楚要捕获什么事件,所以我在图表的父容器中使用了以下内容:

    chart.addEventListener(ChartItemEvent.ITEM_ROLL_OVER,drawLegend);
    

    似乎工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-05
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 2010-12-22
      • 2013-06-22
      • 1970-01-01
      相关资源
      最近更新 更多