饼图与空数据

时间:2010-08-05 11:08:21

标签: flex actionscript-3 pie-chart

当PieSeries中的所有数据等于0时,有没有办法强制Flex绘制空的PieChart。我现在得到的结果只是我的图表所在位置的空白区域。

1 个答案:

答案 0 :(得分:0)

可能不完全是你想要的,但下面的例子会给你一个空的橙色图表,其中一个图例条目标记为空(你可能想保留完整的图例)。

alt text http://img9.imageshack.us/img9/7205/emptypiechart.jpg

禁用标签和数据提示,当所有值都设置为零时,运行一个函数来改变dataProvider(下面的代码可能会有所帮助)

<?xml version="1.0"?>
<!-- charts/BasicPie.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script><![CDATA[
     import mx.collections.ArrayCollection;
     [Bindable]
     public var expenses:ArrayCollection = new ArrayCollection([
        {Expense:"Taxes", Amount:1},
        {Expense:"Rent", Amount:2},
        {Expense:"Bills", Amount:3}
     ]);

     private function removeItems(event:Event):void{

        expenses.removeAll();
        expenses.addItem({Expense:"Empty", Amount:1});
        mySeries.setStyle("labelPosition", "false");
        myChart.showDataTips = false;

     }

  ]]></mx:Script>
  <mx:Panel title="Pie Chart" width="442" height="536">
     <mx:PieChart id="myChart" 
        dataProvider="{expenses}" 
        showDataTips="true"
        themeColor="#121212" alpha="1.0" width="100%" height="100%">
        <mx:series>
           <mx:PieSeries 
                id="mySeries"           
                field="Amount" 
                nameField="Expense" 
                labelPosition="callout"
           />
        </mx:series>
     </mx:PieChart>
     <mx:Button label="Remove items" click="removeItems(event)"/>
     <mx:Legend dataProvider="{myChart}"/>
  </mx:Panel>
</mx:Application>