8

I am using a google chart API in this

how can i use this chart in android application?

here is my code

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       String url =  "http://chart.apis.google.com/chart?cht=p3&chs=500x200&chd=e:TNTNTNGa&chts=000000,16&chtt=A+Better+Web&chl=Hello|Hi|anas|Explorer&chco=FF5533,237745,9011D3,335423&chdl=Apple|Mozilla|Google|Microsoft";
        WebView mCharView = (WebView) findViewById(R.id.char_view);
        mCharView.loadUrl(url);
    }

and the XML

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<WebView android:id="@+id/char_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"/>


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>
1
  • Isn't this deprecated now ?
    – M.Sameer
    Sep 9, 2013 at 11:37

3 Answers 3

13

If you want to load your chart like @Rajesh said you have to use a webview and than load the url of your chart by:

webview.loadUrl(CHART_URL);

add to your manifest

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

but if you are looking how to draw pie chart in android you can see this tutorial it has sample code attached to

enter image description here

1
  • Is there any way to draw pie chart in android app without internet Sep 29, 2015 at 9:00
4

Remember to enable javascript in your webview!

webview.getSettings().setJavaScriptEnabled(true);
3

Use a WebView to display any web content.

webview.loadUrl(CHART_URL);
1
  • it is not working right it gives me WEb page is not available although the URL iam using is giving me Pie chart in the web browser
    – AnasBakez
    May 30, 2012 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.