Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 6
Registered: ‎05-08-2014
My Device: Developer
My Carrier: Blackberry
Accepted Solution

Creating Graph using google chart api but not working

Hello everyone, I want to create line graph using google api in my blackberry appliction, for that I downloaded "blackberry-google-chart-api" and referring this link:

"https://code.google.com/p/blackberry-google-chart-api/source/browse/trunk/blackberry-google-chart-ap... "

but it gives me class not found exception.

Dont know how to solve this issue...thanks..

Contributor
Posts: 49
Registered: ‎12-29-2011
My Device: 9800
My Carrier: vodafone

Re: Creating Graph using google chart api but not working

[ Edited ]

for which class you are getting this exception. have u added
blackberry-google-chart-api jar file correctly in your project lib folder.

Thanks,

New Developer
Posts: 6
Registered: ‎05-08-2014
My Device: Developer
My Carrier: Blackberry

Re: Creating Graph using google chart api but not working

Thanks vishakhaYadav10, I added api in my build path and it is working properly. but now I want to pass my array data to the url. 

My code is:

  

String[] pointArray=(String[]) hashtable.get("point");

 

// where all values are coming from hashtable of my webservice.I want to pass this array as a chart data for line graph.

 

BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField(myBrowserFieldConfig);

add(browserField);

 

String url="http://chart.apis.google.com/chart?&cht=lc&chco=000000&chds=0,10&chdlp=b&chxt=x,y" +
"&chg=1.04,0,5,1&chds=0,30&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,0|s,0000ff,1,-1,0|s,00aa00,2,-1,0" +
"&chs=480x280&chof=validate&chd=t:100,200,300,400,500,600,700&chd=t:"+point";

 

 browserField.requestContent(url);

 

but it gives me error :

The parameter 'chd=t:[Ljava.Lang.String@d297c570f' does not match the expected formate.

 

I want to pass my array to this url for cahrt data.How to solve this problem??? Please help me to sort out this problem.

thanks..

 

 

Contributor
Posts: 49
Registered: ‎12-29-2011
My Device: 9800
My Carrier: vodafone

Re: Creating Graph using google chart api but not working

According to your error, the problem seems in the formation of url and 

in chd=t:100,200,300,400,500,600,700&chd=t:"+point"; part.

 

format :

 

String url="http://chart.apis.google.com/chart?&cht=lc&chco=000000&chds=0,10&chdlp=b&chxt=x,y" +
"&chg=1.04,0,5,1&chds=0,30&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,0|s,0000ff,1,-1,0|s,00aa00,2,-1,0" +
"&chs=480x280&chof=validate&chd=t:"+point";

 

please check once. 

 

Thanks,

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Creating Graph using google chart api but not working

You say the chart is objecting to the text

 

'chd=t:[Ljava.Lang.String@d297c570f'

 

I think the problem is this code:

 

.... 700&chd=t:"+point";

 

When you concatenate an Object to a String, the compiler needs to convert that Object to a String, and will use the Object's

toString()

method to do this.  It looks like the implementation of the toString() for your Object (which appears to be of type Ljava.Lang.String) is using the default toString() method, which outputs the class name and a unique reference.  This is pretty useless for the chart operations.  You need this String to be in a form that is recognisable to the charting API. 

 

I suggest that you convert your Object (the one you have called point) to a String and then print it out to the console using System.out.println(..) to make sure you have it converted it to something that the chart API will understand. 

New Developer
Posts: 6
Registered: ‎05-08-2014
My Device: Developer
My Carrier: Blackberry

Re: Creating Graph using google chart api but not working

Thanks vishakhaYadav10 & peter strange, my problem is solved with following solution:-

String[] pointArray=(String[]) hashtable.get("point");

String url="http://chart.apis.google.com/chart?&cht=lc&chco=000000&chds=0,10&chdlp=b&chxt=x,y" +
"&chg=1.04,0,5,1&chds=0,30&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,0|s,0000ff,1,-1,0|s,00aa00,2,-1,0" +
"&chs=480x280&chof=validate&chd=t:100,200,300,400,500,600,700&chd=t:";

for(int i=0;i<pointArray.length)

{

url = url.concat(mcp[i]);
url = url.concat(",");

}

url = url.substring(0, url.lastIndexOf(','));

browserField.requestContent(url);

Thanks...