tags:

views:

265

answers:

1

hi,

the LineSeries is not dynamically added to my CartesianChart... What's wrong in this code:

...

 private function chartComplete():void {

                var ls:LineSeries = new LineSeries();      
                ls.styleName = 'timeline';
                ls.dataProvider = "{dataManager.tagViewTimelineModel.tags.getItemAt(0).yearPopularity}";
                ls.yField = 'popularity';
                //ls.s = "{new Stroke(0xCC33CC, 2)}";
                AllChart.series[0] = ls; 
            }

...

<mx:CartesianChart id="AllChart"  width="100%" height="100" creationComplete="chartComplete();">

            <mx:horizontalAxis><mx:CategoryAxis id="horiz1"  dataProvider="['1','2','3','4','5','6','7','8','9','10','11','23','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']"/></mx:horizontalAxis>
            <mx:horizontalAxisRenderers><mx:AxisRenderer axis="{horiz1}"/></mx:horizontalAxisRenderers>

            <mx:verticalAxis><mx:LinearAxis id="vert1" /></mx:verticalAxis>
            <mx:verticalAxisRenderers><mx:AxisRenderer axis="{vert1}"/></mx:verticalAxisRenderers>

            <mx:series>
                <mx:AreaSeries id="timeArea" styleName="timeArea" name="A" dataProvider="{dataManager.tagViewTimelineModel.tags.getItemAt(2).yearPopularity}" areaStroke="{new Stroke(0x0033CC, 2)}" areaFill="{new SolidColor(0x0033CC, 0.5)}" />


            </mx:series>

            </mx:CartesianChart>

I can only see the TimeLine if I added it with MXML:

<mx:LineSeries styleName="timeLine" dataProvider="{dataManager.tagViewTimelineModel.tags.getItemAt(0).yearPopularity}" yField="popularity" stroke="{new Stroke(0xCC33CC, 2)}"  />

But I need to update the view, and add N lines so I cannot do it with MXML.

thanks

A: 

You can set the series property for the chart. Just add a new Series object to that array.

CookieOfFortune
do you mean this ? AllChart.series.push(ls); It doesn't work.
Patrick
The listener might only be called when you set the property. So maybe do: series:Array = AllChart.series; series.push(ls); AllChart.series = series;
CookieOfFortune
ok, I've changed and now I have run-time error: "ReferenceError: Error #1069: Property popularity not found on String and there is no default value.".
Patrick
I've tried to swap the lines ls.dataProvider and ls.yLabel after adding your lines, but still same error.
Patrick
you're going to have to show me what structure your data is in. The dataProvider is supposed to point to an ArrayCollection of objects, and the yField is supposed to point to the field in those objects to use as its value.
CookieOfFortune
If I add this MXML line inside series it works, so I guess the dataProvider is not the issue: <mx:LineSeries styleName="timeLine" dataProvider="{dataManager.tagViewTimelineModel.tags.getItemAt(0).yearPopularity}" yField="popularity" stroke="{new Stroke(0xCC33CC, 2)}" />
Patrick
oh, I just noticed. Take off the "{ and }" from your dataProvider values when you are using AS. Flex thought the string literal was your dataProvider.
CookieOfFortune
you are the boss. It worked, thanks!
Patrick