首页 技术 正文
技术 2022年11月18日
0 收藏 552 点赞 3,255 浏览 2615 个字

先引用hellocharts-library-<version>.jar

然后在layout中设置

<lecho.lib.hellocharts.view.PieChartView
android:id="@+id/chart"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
package com.example.chardemo;import java.util.ArrayList;
import java.util.List;import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.PieChartData;
import lecho.lib.hellocharts.model.SliceValue;
import lecho.lib.hellocharts.renderer.PieChartRenderer;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.PieChartView;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;public class MainActivity extends ActionBarActivity
{
private PieChartView chart;
private PieChartData data; private boolean hasLabels = true;//是否在薄片上显示label
private boolean hasLabelsOutside = false;//是否在薄片外显示label
private boolean hasCenterCircle = false;//是否中间掏空一个圈
private boolean hasCenterText1 = true;//掏空圈是的title1
private boolean hasCenterText2 = true;//掏空圈是的title2
private boolean isExploded = false;//薄片是否分离
private boolean hasLabelForSelected = false; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chart = (PieChartView)findViewById(R.id.chart);
generateData(); } private void generateData()
{
int numValues = 3; List<SliceValue> values = new ArrayList<SliceValue>();
for (int i = 0; i < numValues; ++i)
{
SliceValue sliceValue = new SliceValue(
(float) Math.random() * 30 + 15, ChartUtils.pickColor());
sliceValue.setLabel((int)sliceValue.getValue()+"瓶");//设置label
values.add(sliceValue);
} data = new PieChartData(values);
data.setHasLabels(hasLabels);
data.setHasLabelsOnlyForSelected(hasLabelForSelected);
data.setHasLabelsOutside(hasLabelsOutside);
data.setHasCenterCircle(hasCenterCircle); if (isExploded)
{
data.setSlicesSpacing(24);//设置分离距离
} if (hasCenterText1)
{
data.setCenterText1("Hello!"); // Get roboto-italic font.
Typeface tf = Typeface.createFromAsset(this.getAssets(),"Roboto-Italic.ttf");//自定义的字体
data.setCenterText1Typeface(tf); // Get font size from dimens.xml and convert it to sp(library uses
// sp values).
data.setCenterText1FontSize(ChartUtils.px2sp(getResources()
.getDisplayMetrics().scaledDensity, (int) getResources()
.getDimension(R.dimen.pie_chart_text1_size)));
} if (hasCenterText2)
{
data.setCenterText2("Charts (Roboto Italic)"); Typeface tf = Typeface.createFromAsset(this.getAssets(),
"Roboto-Italic.ttf");
data.setCenterText2Typeface(tf);
data.setCenterText2FontSize(ChartUtils.px2sp(getResources()
.getDisplayMetrics().scaledDensity, (int) getResources()
.getDimension(R.dimen.pie_chart_text1_size)));
} chart.setPieChartData(data);
chart.setCircleFillRatio(0.5f);//设置放大缩小范围
}}

HelloCharts pie饼图绘制

效果图

HelloCharts pie饼图绘制

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848