如何使用Google图表API

Ana*_*kez 8 android google-api

我使用的是谷歌的图表API在

我如何在Android应用程序中使用此图表?

这是我的代码

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);
    }
Run Code Online (Sandbox Code Playgroud)

和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>
Run Code Online (Sandbox Code Playgroud)

K_A*_*nas 13

如果你想加载你的图表,像@Rajesh说你必须使用webview,而不是通过以下方式加载你的图表的网址:

webview.loadUrl(CHART_URL);
Run Code Online (Sandbox Code Playgroud)

添加到您的清单

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Run Code Online (Sandbox Code Playgroud)

但如果您正在寻找如何在Android中绘制饼图,您可以看到本教程附有示例代码

在此输入图像描述