AndroidPieChart
AndroidPieChart是一个工具,你可以在 Android 应用 上轻松生成一个漂亮的饼图。
要求
AndroidPieChart需要依赖于以下环境:1. Java 1.6 or 上面
2. Eclipse
3. Android SDK
1获取知识库
请先将这个库克隆到你的工作区。git clone https://github.com/Ken-Yang/AndroidPieChart.git
2.设置 2.1导入到 EclipseFile->Import->Existing Projects into Workspace 2.2将这里库引用到你的项目Right Click on your project -> Properties -> Android -> Add -> <> -> OK
1在你的layout.xml 中添加PieChart视图元素
android:id="@+id/pieChart"android:layout_width="match_parent"android:layout_height="match_parent">
2获取用于绘制饼图的对象finalPieChart pie = (PieChart) findViewById(R.id.pieChart);
3准备数据
请确保你的总数据百分比等于 100%,否则lib将抛出异常并显示任何内容。ArrayList alPercentage =newArrayList();
alPercentage.add(10.0f);
alPercentage.add(20.0f);
alPercentage.add(10.0f);
alPercentage.add(10.0f);
alPercentage.add(10.0f);
alPercentage.add(10.0f);
alPercentage.add(10.0f);
alPercentage.add(10.85f);
alPercentage.add(9.15f);
4使用数据绘制饼图try {
// setting data pie.setAdapter(alPercentage);
// setting a listener pie.setOnSelectedListener(newOnSelectedLisenter() {
@OverridepublicvoidonSelected(intiSelectedIndex) {
Toast.makeText(ChartView.this, "Select index:"+ iSelectedIndex, Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
if (e.getMessage().equals(PieChart.ERROR_NOT_EQUAL_TO_100)){
Log.e("kenyang","percentage is not equal to 100");
}
}
许可证
版权 2013 Ken Yang
在Apache许可以证下许可以证版本 2.0 ("许可以证") ;你可以能不使用这里文件,除了符合许可以证。 你可以获得许可证的副本在*
在规定的法律或者书面许可下,在许可条款下分发的软件在不保证任何种类的担保或者条件的前提下分发,或者明示或者隐含。 查看许可协议下特定语言的许可权限和限制的许可证。