|
"addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Kory Broere on Oct-25-2012 05:54 |
|
I am creating a Trend Line Chart using values supplied by a query, but I get the following error "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type.
I checked previous posts and the most common problem with this type of error appears to be that the data array contains NULL values or non-numeric characters. I have verified that this is not the issue in this case.
If I hard code the data values the chart works, data = Array(209,280,133,301,193,201,115);
If I change it to my array variable I get the error message, data = Array(tagCount);
Any help would be greatly appreciated.
Thank you
|
Re: "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Peter Kwan on Oct-25-2012 18:28 |
|
Hi Kory,
The error means that the array is not an array of numbers. You mentioned that hard coded the data as Array(209,280,133,301,193,201,115) will work. So I think it is possible that your data are really not an array of numbers. It means either your data are not an array, or it is an array, but at least one of the elements is not a number.
For this type of issues, you may use the following methods to diagnose the problem:
(a) Comment out the code that produces the error, and add the following code to display the array contents in the chart title:
temp = "";
for(i = 1; i LE ArrayLen(data); i = i + 1)
temp = temp & "[" & data[i] & "] ";
c.addTitle(temp, "arial.ttf", 8);
If data is really an array, the above code should display the contents of the array in the chart title. Please check if the contents (enclosed by []) are numbers. If there are some empty [], it means some of the elements are empty (and therefore not numbers).
(b) You may try the following code to convert your data to numbers before passing the data to ChartDirector:
for(i = 1; i LE ArrayLen(data); i = i + 1)
data[i] = LSParseNumber(data[i]);
Please kindly let me know what is the result.
Regards
Peter Kwan |
Re: "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Kory Broere on Nov-06-2012 05:53 |
|
Thank you for the quick reply. I added
temp = "";
for(i = 1; i LE ArrayLen(data); i = i + 1)
temp = temp & "[" & data[i] & "] ";
c.addTitle(temp, "arial.ttf", 8);
to the code and it changed the error to "Complex object types cannot be converted to simple values."
When I hard code the data numbers I get the attached values for the chart title.
I also added the LSParseNumber code you sent to my code where I create the array. There was no change to the original error message.
When I cfdump the array, wouldn't it show an empty value?
Thank you
|
Re: "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Peter Kwan on Nov-07-2012 00:30 |
|
Hi Kory,
Is the error "Complex object types cannot be converted to simple values." generated by the line { temp = temp & "[" & data[i] & "] "; }?
As the above line is pure ColdFusion code and does not include any ChartDirector code, the error is likely because data[i] is not a number. According to the error, it may be a "complex object". For example, a column of a query is a complex object (the column is not a value by rows of values), while a column of a row of a query is a simple value.
If the above is the cause of the problem, to solve the problem, you need to create the array data so that data[i] are numbers. If you need further help, is it possible to include the code you are using to construct the data array (including the database and the code used to generate the array)?
Regards
Peter Kwan |
Re: "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Kory Broere on Nov-07-2012 01:46 |
|
I appreciate your assistance with this. I am passing the year variable because the graph will be converted to a rolling 12 month at some point. Here is the code I'm using.
<cfset varFromDate = dateFormat("01/01/" & year(now()),"mm/dd/yyyy")>
<cfset varToDate = dateFormat("12/31/" & year(now()),"mm/dd/yyyy")>
<cfquery name="getQueryCount" datasource="#datasource#">
SELECT DISTINCT DATEPART(Month, visitDate) AS TagMonth , DATEPART(Year, visitDate) AS TagYear
FROM tblSkillVisitDate
WHERE (visitDate BETWEEN '#varFromDate#' AND '#varToDate#') AND (mobile = 0)
ORDER BY TagYear, TagMonth
</cfquery>
<cfset tagCount = ArrayNew(1)>
<cfset temp = ArraySet(tagCount, 1,getQueryCount.recordcount, 0)>
<cfset tagDate = ArrayNew(1)>
<cfset temp = ArraySet(tagDate, 1,getQueryCount.recordcount, 0)>
<cfset i = 0>
<cfoutput query="getQueryCount">
<cfset i = i+1>
<cfquery name="getSkillQueryCount" datasource="#datasource#">
SELECT COUNT(ID) AS queryCount
FROM tblSkillVisitDate
WHERE (DATEPART(Month, visitDate) = #getQueryCount.TagMonth#) AND (DATEPART(Year, visitDate) = #getQueryCount.TagYear#) AND (mobile = 0)
</cfquery>
<cfset tagCount[i] = getSkillQueryCount.queryCount>
<cfset tagDate[i] = monthAsString(getQueryCount.TagMonth)>
</cfoutput>
<cfdump var="#tagCount#" output="browser">
<cfdump var="#tagDate#" output="browser">
<cfscript>
cd = CreateObject("java", "ChartDirector.CFChart");
function Array() {
var result = ArrayNew(1);
var i = 0;
for (i = 1; i LTE ArrayLen(arguments); i = i + 1)
result[i] = arguments[i];
return result;
}
data = Array(209,280,133,301,193,201,134,5);
//data = Array(tagCount);
labels = Array("April","May","June","July","August","September","October","November");
//labels = Array(tagDate);
c = cd.XYChart(600, 450, "0xffffff", "0x000000", 0);
c.setPlotArea(55, 45, 520, 310, "0xffffff", -1, -1, "0xc0c0c0", -1);
c.addLegend(55, 22, False, "", 8).setBackground(cd.Transparent);
c.addTitle("YTD Tag Searches", "Arial", 13, "0xffffff").setBackground("0x067ab4", -1, 1);
/*temp = "";
for(i = 1; i LE ArrayLen(data); i = i + 1)
temp = temp & "[" & data[i] & "] ";
c.addTitle(temp, "arial.ttf", 8);*/
c.yAxis().setTitle("Tag Searches");
c.xAxis().setLabels(labels).setFontAngle(90);
lineLayer = c.addLineLayer();
lineLayer.addDataSet(data, "0xcc9966", "Total Searches").setDataSymbol(cd.SquareSymbol, 7);
lineLayer.setLineWidth(2);
lineLayer.setHTMLImageMap("", "", "title='{xLabel}: {value} Searches'");
trendLayer = c.addTrendLayer(data, "0x008000", "Trend Line");
trendLayer.setLineWidth(2);
trendLayer.setHTMLImageMap("", "", "title='Change rate: {slope|2} searches/per month'");
chart1URL = c.makeSession(GetPageContext(), "chart1");
imageMap1 = c.getHTMLImageMap("");
</cfscript>
<cfoutput>
<img src="getchart.cfm?#chart1URL#" usemap="##map1" border="0" />
<map name="map1">#imageMap1#</map>
</cfoutput>
Hopefully the issue will be blatantly obvious and easily explained. Thank you |
Re: "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Peter Kwan on Nov-07-2012 03:07 |
|
Hi Kory,
Instead of using:
<cfset tagCount[i] = getSkillQueryCount.queryCount>
may be you can try:
<cfset tagCount[i] = getSkillQueryCount["queryCount"][1]>
Then use:
data = tagCount;
Please let me know if this can solve the problem.
Regards
Peter Kwan |
Re: "addDataSet(double[], int, java.lang.String)", but cannot convert argument 1 to the desired type. |
Posted by Kory Broere on Nov-07-2012 05:01 |
|
That was exactly what I needed, thank you very much for your help! |
|