views:

34

answers:

1

Is there any way to force Flex to draw empty PieChart when all data in the PieSeries equals 0. The result I'm getting now is just a blank space in the place where my chart is supposed to be.

A: 

Hi

Probably not exactly what you want, but the example below will give you an empty orange chart, with a single legend entry labeled Empty (you probably want to keep the full Legend).

alt text

Disable the labels and datatips, and when all values are set to zero, run a function to alter the dataProvider (the code below might be of some help)

<?xml version="1.0"?>
<!-- charts/BasicPie.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
  <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>
Brian Bishop
I've additionally set fill to be transparent so it had more 'empty feeling' to it. Not the most elegant solution but it must do since there are no other. Thanks.
2DH
What did you do to make the fill transparent?
Brian Bishop