Get XML chart data where nodes have identical names

Hi,

I am using the Chart object to create charts from an external XML source which I have no control over. The data comes in the following format.

... ... ... ... ... ...

I can set the xpath fine to ‘/rows/row’ but specifying

values: #cell#

I get the values from the first cell where I want to do something like

values: #cell[1]#

Can I achieve this without writing a new load driver?

Thanks,

Emre

Hi,

Can I achieve this without writing a new load driver?

Nope. You’ll need create the new driver.

Here is the example:

dhtmlx.DataDriver.rows = dhtmlx.extend({},dhtmlx.DataDriver.xml); dhtmlx.DataDriver.rows.records = "/*/row"; dhtmlx.DataDriver.rows.tagToObject = function(tag,z){ var b,c,i; z=z||{}; b=tag.childNodes; c = 0; for (i=0; i<b.length; i++){ if (b[i].nodeType==1){ z["data"+c]=this.nodeValue(b[i]); c++; } } return z; } ... var chart = new dhtmlXChart({ value:"#data0#", ... }); chart.load(url,"rows");

Thank You Alexandra. The provided code works perfectly as is.

Alexandra, a quick follow up question. The file I’m working with also has the additional following node:

... ... ... ... ... ... ... ... ...


where the node stores the field names for each of the cells. Is the parsed XML document exposed in any way - I’d like to use the field names from the node in the legend when doing things like multiple series.

Thanks,

Emre

Emre,

legend items are defined in text property:

dhtmlxChart/samples/06_bar_chart/06_series.html

You can load xml/json before chart initialization, parse this xml/json to get legend and data values. Then you can call chart initialization.
The solution that I provided in previous post doesn’t match in this case.