javagoogle-maps-api-3blackberryblackberry-simulator

how to use Google Line Chart API for passing dynamic data in Blackberry application?


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 this error :

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

I want to pass my array to this URL for chart data. How to solve this problem?


Solution

  • In url

    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;
    

    Your point is converted with point.toString() and appended to the url in this part

    "&chd=t:"+point;
    

    which is the second time when chd appers in the url. So in effect only the last chd value is considered. And the first which was chd=t:100,200,300,400,500,600,700 is not considered.

    If you want to pass chd it has to be in format chd=t:val,val,val where val represents a value from your data. See an example with a data chd=t:-5,30,-30,50,80,200

    and chd should appear only once in the url.

    So your code for the url would be this:

    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:"+<comma separated list of values>;