微信公众号:伴职创作
IT类、哲学、散文、叙事情感类、小说…欢迎你来投稿。
这篇文章只是对MPAndroidChart进行简单的介绍,关于MPAndroidChart的具体使用,会在后续的文章中一一补充。
MPAndroidChart是github上最流行的Android开发图表的开源组件之一,也是Android开发常用框架之一。
A powerful ? Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, dragging and animations.
一、Gradle引入
在Android工程下的build.gradle文件中添加如下代码:
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
二、Maven引入
<!-- <repositories> section of pom.xml -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<!-- <dependencies> section of pom.xml -->
<dependency>
<groupId>com.github.PhilJay</groupId>
<artifactId>MPAndroidChart</artifactId>
<version>v3.1.0</version>
</dependency>
其中MPAndroidChart:v3.1.0版本是基于Androidx开发,而在本文开发的案例中将会使用MPAndroidChart:v3.0.3版本。
关于MPAndroidChart的基础方法,这里先介绍图表Chart的常用方法,对于Legend图例和Description描述的常用方法将在下文中针对具体的实例来进行介绍。
// 是否显示中间的洞
PieChart.setDrawHoleEnabled(boolean enabled);
// 设置中间洞的大小
PieChart.setHoleRadius(int radius);
// 半透明圈
PieChart.setTransparentCircleRadius(float percent);
// 设置半透明圆圈的颜色
PieChart.setTransparentCircleColor(int color);
// 设置半透明圆圈的透明度
PieChart.setTransparentCircleAlpha(int alpha);
// 饼状图中间可以添加文字
PieChart.setDrawCenterText(boolean enabled);
// 设置中间文字
PieChart.setCenterText(CharSequence text);
// 中间文字的颜色
PieChart.setCenterTextColor(int color);
// 中间文字的大小px
PieChart.setCenterTextSizePixels(float sizePixels);
// 中间文字半径百分比
PieChart.setCenterTextRadiusPercent(float percent);
// 中间文字的样式
PieChart.setCenterTextTypeface(Typeface t);
// 中间文字的偏移量
PieChart.setCenterTextOffset(float x, float y);
// 初始旋转角度
PieChart.setRotationAngle(float angle);
// 可以手动旋转
PieChart.setRotationEnabled(boolean enabled);
// 显示成百分比
PieChart.setUsePercentValues(boolean enabled);
// 是否显示每个部分的文字描述
PieChart.setDrawEntryLabels(boolean enabled);
// 描述文字的颜色
PieChart.setEntryLabelColor(int color);
// 描述文字的大小
PieChart.setEntryLabelTextSize(float size);
// 描述文字的样式
PieChart.setEntryLabelTypeface(Typeface tf);
// 图标的背景色
PieChart.setBackgroundColor(int color);
// 设置pieChart图表转动阻力摩擦系数[0,1]
PieChart.setDragDecelerationFrictionCoef(float newValue);
// 设置pieChart扇形区点击事件
PieChart.setHighlightPerTapEnabled(boolean enabled);
更多目录…