Google Chart API 之生成二维码
来源:互联网 发布:福建三千万美元知乎 编辑:程序博客网 时间:2024/03/29 04:53
完成源代码下载http://download.csdn.net/detail/wujiaqi168/6764395
Google提供的网络服务API中,最受好评的莫过于Google Chart API了。只要通过它,程序设计人员不需要具备太高深的功力,也不需要具备GD library的知识,就能够做出漂亮的图表、专业的分析报表。
Google chart API 地址如下:
http://chart.apis.google.com/chart
Google chart API 提供下列类型的图表。
LIne charts
Bar charts
Pie charts
Venn diagrams
Scatter plots
Radar charts
Maps
Google-0-meters
QR codes
Google chart API 提供的请求参数如下:
* cht(chart type):图表种类,cht=p3表示生成3D饼图。
* chs(chart size):图表面积,chs=250x100表示宽200像素,高100像素。
* chtt(chart title):图表标题,chtt=Hello+World表示标题是Hello World。
* chd(chart data):图表数据,chd=s:hW表示数据是普通字符串(simple string)hW。
下面我将就利用Google Chart API 来生成QR codes 二维码举例,来向大家展示如何使用Google chart API:
在布局文件中,我简单地设计了edittext,button,webview三个组件,edittext用来输入生成二维码中包含的信息,button用来点击产生二维码,webview用来显示生成的二维码。
布局文件main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/white"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/myEditText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<Button
android:id="@+id/myButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
<WebView
android:id="@+id/myWebView1"
android:background="@drawable/white"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>
主程序代码如下:
package Demo.GoogleChartAPITest;
import java.net.URLEncoder;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class GoogleChartAPITestActivity extends Activity {
private Button mButton01;
private EditText mEditText01;
private WebView mWebView01;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView01 = (WebView)findViewById(R.id.myWebView1);
mButton01 = (Button)findViewById(R.id.myButton1);
mEditText01 = (EditText)findViewById(R.id.myEditText1);
mButton01.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
///Log.i("halfcool", mEditText01.getText().toString());
if (mEditText01.getText().toString()!="") {
//Log.i("halfcool", mEditText01.getText().toString());
/*webview加载数据*/
mWebView01.loadData(GenGoogleQRChart(mEditText01.getText().toString(),250), "text/html", "utf-8");
}
}
});
}
protected String GenGoogleQRChart(String strToQRCode, int strWidth) {
String strReturn = "";
try {
strReturn = new String(strToQRCode.getBytes("utf-8"));
strReturn = "<html><body>" + "<img src=http://chart.apis.google.com/chart?chs="
+ strWidth + "x" +strWidth + "&chl=" +
URLEncoder.encode(strReturn, "utf-8") +
"&choe=UTF-8&cht=qr></body><html>";
}
catch (Exception e) {
e.printStackTrace();
}
return strReturn;
}
}
- Google Chart API 之生成二维码
- 使用Google Chart API生成二维码以及制作点子名片
- Google Chart API 生成图片
- 二维码生成(Google-API)
- google api 生成二维码
- 利用Google Chart服务生成二维码
- 利用Google Chart服务生成二维码
- 利用Google API生成二维码
- Google二维码在线生成API
- 利用Google API生成二维码
- Google Chart API 自动生成图表
- 利用Google API快速生成QR二维码
- 生成二维码的google开放api接口
- Google Chart Api
- Google Chart API
- Google Chart API
- Google Chart API
- 初识Google Chart API
- 项目视频讲解_马震宇-博客
- EL 表达式
- 共模与差模
- mysql 数据库基本操作
- Python群发邮件
- Google Chart API 之生成二维码
- jquery ui
- 【实验】手写数字识别--logistic regression
- 电路设计中的工程计算
- JSTL标签库
- 嵌入式Linux启动过程中的问题积累
- 学习笔记----快速幂取模算法
- 容器 C++ set和map
- Android 开发Tips