开发者

Hide Chart Items based on some value

I have plot chart with an 'itemRenderer' to render the text. I have the renderer working corrrectly. Now, what I want to show/hide some of the chart tiems if it's below/above some value. I am using the 'Label' component as 'itemRenderer' and overriding the 'data' function (Please fin开发者_Go百科d my renderer component below..).

If the size of the dataprovider of the chart is greater than '100', I want to hide all the 'events' with 'low' severity. For that I need to get a reference to the dataprovider, but not sure how... ?

Has anyone come across this problem ?

public class EventChartItemRenderer extends Label
{
    private var chartItem:ChartItem;
    private var evtLblTxt:String;
    private var txtBorderColor:uint;
    private var showHide:Boolean;

    public function EventChartItemRenderer()
    {
        super();
    }

    override public function set data(val:Object):void {

        chartItem = val as ChartItem;

        var event:DeviceEventDetails = chartItem.item as DeviceEventDetails;
        if(event.severity == 2){
            evtLblTxt = "2";
            txtBorderColor = 0xFFD685;
            showHide = false;
        }else if(event.severity == 4){
            evtLblTxt = "4";
            txtBorderColor = 0xE68D53;
            showHide = true;
        }else if(event.severity == 6){
            evtLblTxt = "6";
            txtBorderColor = 0xB870DB;
            showHide = true;
        }
    }

    override public function get data():Object {

        return chartItem;
    }

    override protected function commitProperties():void {

        super.commitProperties();
        if(!showHide) return;
        this.text = evtLblTxt;
        this.setStyle("color", txtBorderColor);
        this.setStyle("fontWeight", "bold");
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

        super.updateDisplayList(unscaledWidth, unscaledHeight);

        if(!showHide) return;
        var rc:Rectangle = new Rectangle(0, 0, unscaledWidth, unscaledHeight);
        var g:Graphics = graphics;
        g.clear();        
                    g.moveTo(rc.left, rc.top);
        g.lineStyle(1, txtBorderColor, 0.8);
        g.lineTo(rc.width, rc.top);
        g.lineTo(rc.width, rc.bottom+4);
        g.lineTo(rc.left, rc.bottom+4);
        g.lineTo(rc.left, rc.top);
        g.endFill();    
    }
}

It's actually chartItem.element. And you need to cast it to 'ChartElement' because the 'element' refers to an interface 'IChartElement' and access the 'dataProvider' property. The 'chartDataProvider' is write-only. So, the correct way of accessing it is...

(chartItem.element as ChartElement).dataProvider.


ChartItem has an IChartElement property with access to the chart data provider:

chartItem.item.chartDataProvider.length > 100
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜