Using Array...

I am using ObjectPlanet’s EasyCharts bean to do charts in my system, and am having a probably very basic problem… In the below two lines of code I declare an array then gather four values from the current foundset into that array:

var YaxisLabels = new Array();
YaxisLabels = databaseManager.getFoundSetDataProviderAsArray(foundset,'wsyear');

Debugger shows it works, and the array is populated as [2007,2008,2009,2010] but when EasyCharts tries to use those values it gives the error:

org.mozilla.javascript.EvaluatorException: Cannot convert [Ljava.lang.Object;@1b1b76e to java.lang.String (Chart, line 26)

If I replace the databaseManager call with the text [2007,2008,2009,2010] in the method, the whole thing works. Why can’t it work from the array itself?

Thanks in advance… :D

ellen

Looks like easychart really wants Strings.

Why don’t you try to do something like

for (var i = 1; i <= foundset.getSize(); i++) {
var record = foundset.getRecord(i);
YaxisLabels = record.wsyear + '';
}

Patrick - tried your code, and with a few modifications I got it to construct the string. Now I get:

org.mozilla.javascript.EvaluatorException: Cannot convert [2007,2008,2009,2010] to java.lang.String (Chart, line 27)

Here is what I’m using:

for (var i = 1; i <= foundset.getSize(); i++) {
var record = foundset.getRecord(i);
YaxisLabels = YaxisLabels + record.wsyear + ',';
}

But that left the extra comma – so I took it off. But that still didn’t work, so I added the brackets in case that would mean something:

chart.sampleLabels = "[" + utils.stringLeft(YaxisLabels, YaxisLabels.length-1) + "]"

This is what produces the error above. Other ideas?

The brackets are there to create/show an array.

What happens here imho is that you triyto use an Array of integers whereas the plugin wants an Array of String values.

When you add, like patricks suggested, a “” (empty string) to every integer value in the Array it should work. This way JavaScript will typecast your integer value to a String.

Hope this helps

Sorry, I wasn’t clear. I tried Patrick’s code first, and did things like the comma and brackets only afterward. Just switched it back to:

for (var i = 1; i <= foundset.getSize(); i++) {
var record = foundset.getRecord(i);
YaxisLabels = record.wsyear + "";
}
chart.sampleLabels = YaxisLabels

And I get this in response:

org.mozilla.javascript.EvaluatorException: Cannot convert 2006 to java.lang.String

Also tried it with a space in the quotes, using single quotes instead of double, and changing it to YaxisLabels = YaxisLabels + record.wsyear + “”; since without that it’s making the whole pseudo-array only show the first year.

Sorry if I’m being dense! I see what you guys are trying to do. EasyCharts accepts my integers from an array for the Yaxis itself – it’s the labels it seems to demand a string I can’t figure out for…

Ellen, you are half way there. I think you changed 2006 into a string (when I follow your code) but now you should make it an arraychart.sampleLabels = [YaxisLabels]or```
chart.sampleLabels = new Array(YaxisLabels)*