Android 如何使用谷歌图表 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10814142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Google chart API
提问by AnasBakez
I am using a google chart API in this
我在这个使用谷歌图表 API
how can i use this chart in android application?
我如何在 android 应用程序中使用这个图表?
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
<?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>
回答by K_Anas
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:
如果你想像@Rajesh 那样加载你的图表,你必须使用 webview 而不是通过以下方式加载图表的 url:
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 tutorialit has sample code attached to
但如果您正在寻找如何在 android 中绘制饼图,您可以查看本教程,其中附有示例代码
回答by Hans En
Remember to enable javascript in your webview!
记得在你的 webview 中启用 javascript!
webview.getSettings().setJavaScriptEnabled(true);