前言
在项目当中很多时候要对数据进行分析就要用到图表,在gitHub上有很多优秀的图表开源库,今天给大家分享的就是MPAndroidChart中的柱状图。简单介绍一下MPAndroidChart:他可以实现图表的拖动,3D,局部查看,数据动态展示等功能。
官方源码地址:github.com/PhilJay/MPA…
废话就不多说了,先给看大家看看效果图
操作步骤
第一步:需要将依赖的库添加到你的项目中
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
implementation 'com.google.android.material:material:1.0.0'
第二步:xml中
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
复制代码
第三步:ValueFormatter.java
/**
* Class to format all values before they are drawn as labels.
*/
public abstract class ValueFormatter implements IAxisValueFormatter, IValueFormatter {
/**
* <b>DO NOT USE</b>, only for backwards compatibility and will be removed in future versions.
*
* @param value the value to be formatted
* @param axis the axis the value belongs to
* @return formatted string label
*/
@Override
@Deprecated
public String getFormattedValue(float value, AxisBase axis) {
return getFormattedValue(value);
}
/**
* <b>DO NOT USE</b>, only for backwards compatibility and will be removed in future versions.
* @param value the v