github地址:https://github.com/PhilJay/MPAndroidChart


添加依赖:

  • Add the following to your project level build.gradle:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
  • Add this to your app build.gradle:
dependencies {
compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
}

下载Demo演示,修改成自己的需求即可
如饼图的示例代码:
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics; import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry; import java.util.ArrayList; public class MainActivity extends AppCompatActivity {
private PieChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mChart = (PieChart) findViewById(R.id.pieChart);
PieData mPieData = getPieData(4, 100);
showChart(mChart, mPieData);
} private void showChart(PieChart pieChart, PieData pieData) {
pieChart.setHoleColor(Color.TRANSPARENT);
pieChart.setHoleRadius(60f); //半径
pieChart.setTransparentCircleRadius(64f); // 半透明圈
//pieChart.setHoleRadius(0) //实心圆
Description description = new Description();
description.setText("测试饼状图");
pieChart.setDescription(description);
// mChart.setDrawYValues(true);
pieChart.setDrawCenterText(true); //饼状图中间可以添加文字
pieChart.setDrawHoleEnabled(true);
pieChart.setRotationAngle(90); // 初始旋转角度
pieChart.setRotationEnabled(true); // 可以手动旋转
pieChart.setUsePercentValues(true); //显示成百分比
pieChart.setCenterText("测试"); //饼状图中间的文字
pieChart.setCenterTextSize(18);
//设置数据
pieChart.setData(pieData);
Legend mLegend = pieChart.getLegend(); //设置比例图
mLegend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART); //最右边显示
// mLegend.setForm(LegendForm.LINE); //设置比例图的形状,默认是方形
mLegend.setXEntrySpace(7f);
mLegend.setYEntrySpace(5f);
pieChart.animateXY(1000, 1000); //设置动画
} /**
*
* @param count 分成几部分
* @param range
*/
private PieData getPieData(int count, float range) {
ArrayList<String> xValues = new ArrayList<String>(); //xVals用来表示每个饼块上的内容
for (int i = 0; i < count; i++) {
xValues.add("Quarterly" + (i + 1)); //饼块上显示成Quarterly1, Quarterly2, Quarterly3, Quarterly4
} ArrayList<PieEntry> yValues = new ArrayList(); //yVals用来表示封装每个饼块的实际数据
// 饼图数据
/**
* 将一个饼形图分成四部分, 四部分的数值比例为14:14:34:38
* 所以 14代表的百分比就是14%
*/
float quarterly1 = 14;
float quarterly2 = 14;
float quarterly3 = 34;
float quarterly4 = 38;
yValues.add(new PieEntry(quarterly1, 0));
yValues.add(new PieEntry(quarterly2, 1));
yValues.add(new PieEntry(quarterly3, 2));
yValues.add(new PieEntry(quarterly4, 3));
//y轴的集合
PieDataSet pieDataSet = new PieDataSet(yValues, "Quarterly Revenue 2014"/*显示在比例图上*/);
pieDataSet.setSliceSpace(0f); //设置个饼状图之间的距离
ArrayList<Integer> colors = new ArrayList<Integer>();
// 饼图颜色
colors.add(Color.rgb(205, 205, 205));
colors.add(Color.rgb(114, 188, 223));
colors.add(Color.rgb(255, 123, 124));
colors.add(Color.rgb(57, 135, 200));
pieDataSet.setColors(colors);
DisplayMetrics metrics = getResources().getDisplayMetrics();
float px = 5 * (metrics.densityDpi / 160f);
pieDataSet.setSelectionShift(px); // 选中态多出的长度
PieData pieData = new PieData(pieDataSet);
return pieData;
}
}

activity_main.xml

 <com.github.mikephil.charting.charts.PieChart
android:id="@+id/pieChart"
android:layout_width="match_parent"
android:layout_height="320dp"
/>
 

android开源图表库MPAndroidChart(曲线图、直方图、饼状图)的更多相关文章

  1. 我的Android进阶之旅------>【强力推荐】Android开源图表库XCL-Charts版本发布及展示页

    因为要做图表相关的应用,后来百度发现了一个很好的Android开源图表库(XCL-Charts is a free charting library for Android platform.) 下面 ...

  2. Android开源图表库介绍

    XCL-Charts XCL-Charts V1.8     Android开源图表库(XCL-Charts is a free charting library for Android platfo ...

  3. Android开源图表库XCL-Charts版本号公布及展示页

    XCL-Charts V2.1 Android开源图表库(XCL-Charts is a free charting library for Android platform.) XCL-Charts ...

  4. Android图表库MPAndroidChart(三)——双重轴线形图的实现,这次就so easy了

    Android图表库MPAndroidChart(三)--双重轴线形图的实现,这次就so easy了 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库 ...

  5. android 开源图表库MPChart最简单使用方法示例教程Demo--折线图 柱状图

    转载请注明本文出处:http://blog.csdn.net/wingichoy/article/details/50428246 MPChart是android上一款强大的图表开源库,他可以轻松的绘 ...

  6. JS图表插件(柱形图、饼状图、折线图)

    http://www.open-open.com/lib/view/open1406378625726.html

  7. Android图表库MPAndroidChart(五)——自定义MarkerView实现选中高亮

    Android图表库MPAndroidChart(五)--自定义MarkerView实现选中高亮 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库MP ...

  8. Android图表库MPAndroidChart(四)——条形图的绘制过程过程,隐隐约约我看到了套路

    Android图表库MPAndroidChart(四)--条形图的绘制过程过程,隐隐约约我看到了套路 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库 ...

  9. Android图表库MPAndroidChart(二)——线形图的方方面面,看完你会回来感谢我的

    Android图表库MPAndroidChart(二)--线形图的方方面面,看完你会回来感谢我的 在学习本课程之前我建议先把我之前的博客看完,这样对整体的流程有一个大致的了解 Android图表库MP ...

随机推荐

  1. 11、find查找

    1.find查找概述 为什么要有文件查找,因为很多时候我们可能会忘了某个文件所在的位置,此时就需要通过find来查找. find命令可以根据不同的条件来进行查找文件,例如:文件名称.文件大小.文件修改 ...

  2. docker常用命令与容器创建

    ################docker安装##################### Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个 ...

  3. PAT Basic 1016 部分A+B (15 分)

    正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 8,D​A​​=6,则 A 的“6 部分”P​A​​ 是 66,因为 A 中有 ...

  4. CAS JDK 证书错误学习笔记

    通过之前生产上发现的问题总结得出以下结论:  问题现象就是:由F5 进行分发到cas 两个服务端 导致 客户端访问时  (时好时坏的现象 ) 通过在服务端的查看apahce 的访问日志得出的结论  发 ...

  5. c#图像处理的简单算法

    原文链接:https://blog.csdn.net/wchstrife/article/details/78984735 使用C#进行图像处理前言之前一直认为图像处理是一件很高大上的事情,在一门选修 ...

  6. 在qt的QOpenGLWidget开启opengl的抗锯齿

    在QOpenGLWidget的构造函数添加下面几句代码即可 QSurfaceFormat surfaceFormat; surfaceFormat.setSamples();//多重采样 setFor ...

  7. 10、堆叠窗口StackedWidget

    新建项目,基类选择QMainWindow,勾选ui 堆叠窗口有三个page,每个page有个label   button处,快捷菜单,转到槽,添加代码 void MainWindow::on_push ...

  8. 《剑指offer》算法题第一天

    按照个人计划,从今天开始做<剑指offer>上面的算法题,练习平台为牛客网,上面对每道题都有充分的测试实例,感觉还是很不错的.今天下午做了四道题,分别为: 1. 二叉树的深度(书55题) ...

  9. ​直接插入排序(Straight Insertion Sort)

    1.定义 直接插入排序(Straight Insertion Sort)的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表. 插入排序(Insertion Sort ...

  10. 2018美团CodeM编程大赛初赛B轮 A题开关灯

    题目描述 美团的办公室一共有n层,每层有m个会议室,可以看成是一个n*m的网格图.工程师们每天的工作需要协作的地方很多,经常要到会议室开会解决各种问题.公司是提倡勤俭节约的,因此每次会议室只在使用时才 ...