开发者

flex chart columnseries not visible

开发者 https://www.devze.com 2023-03-15 14:54 出处:网络
I have a flex chart that I\'m trying to build via actionscript dynamically. For test purposes I came up with the following data structure and code:

I have a flex chart that I'm trying to build via actionscript dynamically. For test purposes I came up with the following data structure and code:

Bindable]
        public var columnDat:Array= 
        [{signalID:"SCL", point2:100},
        {signalID:"SCL", point2:50},
        {signalID:"SCL", point2:30},
        {signalID:"SCL", point2:60},
        {signalID:"SCL", point2:220},
        {signalID:"SCL", point2:140},
        {signalID:"SCL", point2:280}];

public function makeDummyChart(genericChart:CartesianChart, genericLegend:Legend, chartPanel:ChartPanel):void {

            var renderers:ArrayCollection = new ArrayCollection();
            开发者_运维技巧genericChart = new ColumnChart();

            // Define the two axes.
            var dispAxis:CategoryAxis = new CategoryAxis();
            var axr:AxisRenderer = new AxisRenderer();              
            axr.axis = dispAxis;
            renderers.addItem(axr); 

            var seriesList:ArrayCollection=new ArrayCollection();

            // Add the series
            genericChart.horizontalAxis = dispAxis;
            var columnSeries:ColumnSeries = new ColumnSeries();     
            BindingUtils.bindProperty(columnSeries, "dataProvider", this, "columnDat");

            columnSeries.xField="signalID";;
            columnSeries.yField="point2";
            seriesList.addItem(columnSeries);

            genericChart.series = seriesList.toArray();
            genericLegend.dataProvider = genericChart;

            genericChart.horizontalAxisRenderers = renderers.toArray();

            genericLegend.dataProvider = genericChart;
            // chart panel is just the panel on the screen where chart is displayed
            chartPanel.addChild(genericChart);
                trace ("  make dummy chart done");

        }

I just get a blank chart when I run this code.


Can't test it by now, but it should be sufficient if you just assign the columnDat array to the series:

columnSeries.dataProvider = columnDat;

or to the column chart:

genericChart.dataProvider = columnDat;


First, you should probably use MXML for this stuff. It's easier.

Second, I don't think you followed the example very well. There's 2 ways of doing charts:

1) Add data to the chart data provider and have the series specify the x and y field within that data provider.

2) Don't add data to the chart and just add the data directly into series without specifying the x and y field.

Right now, you're doing a mix of both 1 and 2 and the series can't see the data because it's being filtered out, which is why it's blank. Don't set the data provider on the series, but set it on the chart instead and it should work. For further example, look at the docs.

0

精彩评论

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