1 Reply Latest reply on Dec 3, 2007 5:03 PM by peterent

    Data Charts and Radio Buttons

      I'm new to flex and need some help with a project of mine. I want to be able to take a poll (using Radio Buttons) and create from that info a chart. I've tried everything I know how, but I can't get it to work. I know I need a dataprovider tag somewhere but how to create the data from that poll to create the model and the data provider? Any help would be great.


        • 1. Re: Data Charts and Radio Buttons
          peterent Level 2
          A dataProvider for a chart (or list) is based on one of the Collection classes, usually ArrayCollection. So if you want to create a chart of say the number of people who responded to a question broken down by their ages, you might have a table like this:

          Age Response
          18 a
          22 b
          23 a
          18 b

          That tells me you want use an ArrayCollection:

          [Bindable] private var chartData:ArrayCollection;
          chartData = new ArrayCollection();
          chartData.addItem( { age:18, value:"a"} );
          chartData.addItem( {age:22, value:"b"} );

          Now you have an ArrayCollection of Objects, each of which has an age property and a value property. Now you can apply this to a chart:

          <mx:ColumnChart dataProvider="{chartData}"... >
          <mx:ColumnSeries yField="value" />
          <mx:horizontalAxis><mx:CategoryAxis categoryField="age" dataProvider="{chartData}" /></mx:horizontalAxis>

          You can define the chart in MXML and modify or create the data in ActionScript.