Thanks Tariq. I've looked at that example earlier but it doesn't
quite work properly to do what I'm trying. The example uses an
already known ArrayCollection and thus the yField of the different
series can be set very easily.
In my case, I'm getting an XML and then I'm not sure how to set up
my yField/xField. Do I need to parse the XML and create an
ArrayCollection first, or is there a simpler approach? Below is what
I have done, but the series does not show up.
In my mxml, I have:
[Bindable]
public var _elements:XMLList;
public function createXMLList(data:String):XMLList
{
var _xml:XML = new XML(data);
_elements = _xml.elements();
return _elements;
}
<mx:Panel width="450" height="400" id="panel" >
<mx:LineChart id="chart" height="350" width="300"
paddingLeft="5" paddingRight="5"
showDataTips="true" visible="false"
dataProvider="{_elements}">
<mx:horizontalAxis>
<mx:CategoryAxis dataProvider="[EMAIL PROTECTED]" />
</mx:horizontalAxis>
</mx:LineChart>
</mx:Panel>
In my html file, I use the XMLHttpRequest to get my xml and do the
following:
function createChart() {
if (req.readystate == 4 && req.status == 200) {
var seriesArray = new Array();
var flexApp = FABridge.example.root();
var chart = flexApp.getPanel().getChildByName("chart");
var s = FABridge.example.create("mx.charts.series.LineSeries");
flexApp.createXMLList(req.responseText);
s.set("yField", "datapoint");
seriesArray.push(s);
chart.setSeries(seriesArray);
chart.setVisible("true");
}
}
My XML file has the following structure:
<?xml version="1.0" encoding="utf-8"?>
<result metricDfn="Price">
<company1 id="1">
<datapoint date="Jan">50</datapoint>
<datapoint date="Feb">60</datapoint>
<datapoint date="Mar">40</datapoint>
<datapoint date="Apr">50</datapoint>
<datapoint date="May">40</datapoint>
</company1>
</result>
Anything obvious that I'm not doing right?
Thanks,
Mehul.
>Re: [flexcoders] Re: Programatically creating LineSeries
>
>
>1) If you're able to get the XML in a way that you're comfortable,
>I would say don't worry about it. Data Services will be worth
>looking into down the line if you're doing a lot of transactions or
>a lot of data.
>
>2) Here's an example of how to dynamically create series to a chart:
>http://www.cflex.net/showFileDetails.cfm?
>ObjectID=489&Object=File&ChannelID=1
>
>
>Mehul Doshi wrote:
>Could someone please look at my post below and provide me some help?
>
>Thanks.
>--- In [email protected], "Mehul Doshi" <[EMAIL PROTECTED]>
>wrote:
>
> Hi,
>
> I have a few questions on how I should go about achieving
something
> using Flex Charting.
>
> I have a Java servlet/controller that will return XML data. The
data
> will consist of multiple datapoints for multiple companies. Let's
> assume that the xml follows the below structure:
>
> <company1 name="ABC">
> <datapoint date="Jan">50</datapoint>
> <datapoint date="Feb">70</datapoint>
> </company1>
> <company2 name="DEF">
> <datapoint date="Jan">70</datapoint>
> <datapoint date="Feb">50</datapoint>
> </company2>
>
> Using this XML, I need to programatically (using
> Javascript/Actionscript) create a chart with multiple LineSeries
and
> set the dataprovider for each.
>
> My questions are:
>
> 1. How do I obtain the XML data? I'm currently using
XMLHttpRequest
> to get it...any better approach? Do I need to use the DataServices
> feature of Flex?
> 2. Using my current approach, I'm not sure how I can set the
> dataprovider (and xfield,yfield) for each LineSeries (each
company)?
>
> Thanks,
> Mehul.
>