Matt Dell
Matt Dell

Reputation: 9541

Flex Chart Labels don't update on data refresh? (pic)

alt text http://www.mattdell.com/hostedfiles/flexchartissue.bmp

I am having an issue where the chart labels on my Flex Pie Chart don't go away when the data is refreshed. In the picture above, the left/before chart is how the chart loads by default. By choosing another item from a drop down, the chart changes to the right/after chart, but the "At Risk" label does not go away. The same goes for another selection where "In Work" does no go away.

Has anyone else had this happen to them? I can't find ANY information on this!

Thanks!

-Matt

Upvotes: 0

Views: 6311

Answers (3)

Cristian Gómez
Cristian Gómez

Reputation: 1

The solution proposed by Eric Belair works great to me, here's my code in the function that updates de data in infoPA, the dataProvider of the PCgrafico PieChart. I hope it can helps if anyone is experiencing this too

infoPA=evt.result.data.infoPA.estado;

PCgrafico.series=null;
var vectorSeries:Array=new Array();

var series:PieSeries=new PieSeries();
series.field="totalPA";            
series.nameField="estadoPA";
series.setStyle("labelPosition", "callout");
series.setStyle("showDataEffect", effect);
vectorSeries.push(series);
PCgrafico.series=vectorSeries;

Upvotes: 0

Eric Belair
Eric Belair

Reputation: 10702

I ran into this problem and it took me a while to figure out a workaround for this bug.

To fix this, I set the PieChart series when the dataProvider's underlying Collection is set and anytime that Collection changes:

<?xml version="1.0" encoding="utf-8"?>
<mx:PieChart xmlns:mx="http://www.adobe.com/2006/mxml"
    dataProvider="{dataForPieChart}">
    <mx:Script>
        <![CDATA[
            import mx.events.CollectionEvent;
            import mx.collections.ArrayCollection;
            import mx.charts.series.PieSeries;

            [Bindable]
            private var _dataForPieChart:ArrayCollection;

            public function set dataForPieChart(value:ArrayCollection):void
            {
                _dataForPieChart = value;

                /* Add a Collection Change Event Listener to the Collection. */
                _dataForPieChart.addEventListener(
                    CollectionEvent.COLLECTION_CHANGE, 
                    dataForPieChart_collectionChangeHandler);

                reloadPieSeries();
            }

            public function get dataForPieChart():ArrayCollection
            {
                return _dataForPieChart;
            }

            private function dataForPieChart_collectionChangeHandler(
                event:CollectionEvent):void
            {
                reloadPieSeries();
            }

            private function reloadPieSeries():void
            {
                series = new PieSeries();

                series.field = "myValue";

                series.labelPosition = "callout";
            }
        ]]>
    </mx:Script>
</mx:PieChart>

Upvotes: 5

mweiss
mweiss

Reputation: 1373

What does your data look like in both cases? My guess is that you have series data whose value is 0, which may cause the label to render without any visible slice showing up on the pie chart. Try filtering out data with 0 values or using a custom label function to not display the label if the field value is 0.

(Note this is just a guess)

Upvotes: 1

Related Questions