Question

We are trying a prototype using Google chart api.

http://chart.apis.google.com/chart?chf=bg,s,000000&chxs=0,FFFFFF00,9.5&chxt=x&chs=500x300&cht=p3&chco=3072F3|FF9900|80C65A|990066&chd=t:50,5,5,40&chdl=50%C2%B0%20Apples|5%C2%B0%20Oranges|5%C2%B0%20Dates|40%C2%B0%20Strawberries&chdlp=b&chp=0.1

enter image description here

the problem is when we see the chart in the browser it displays the legend. but when we use the BitmapFactory to download the image to an ImageView or even SD card the Legend goes missing (this happens irrespective of where the legend is placed top, bottom, left or right).

here is the code

private Bitmap loadChart(URL url){
    Bitmap chart = null;   

    try{            
        HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
        httpConnection.setDoInput(true);
        httpConnection.connect();

        InputStream is = httpConnection.getInputStream();           
        chart = BitmapFactory.decodeStream(is);


    } catch (IOException e) {       
        e.printStackTrace();
    }

    //MediaStore.Images.Media.insertImage(getContentResolver(), chart, "chart.png", "chart.png");

    return chart;
}

here is the image which was downloaded by the commented line.

we also noticed that, the dimension of the chart specified in URL (chs=500x300) matches with the image dimension as well.

enter image description here

Was it helpful?

Solution

Ended up using webview which handles url encoding without any additional effort.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top