效果:
一,添加依赖:
1 . 在project的build.gradle中添加依赖:
repositories {
//......//
maven { url "https://jitpack.io"}//chart需求
}
2 . 在app的build.gradle中添加依赖:
dependencies {
//......//
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
}
二,布局文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- 线形图表 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:divider="@drawable/spacer_medium8"
android:showDividers="middle"
android:background="#ffd2d2">
<TextView
android:id="@+id/chart_btn_LineChart"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:background="@color/btn_gray"
android:padding="8dp"
android:text="线形图表"
android:textColor="@color/btn_white"
android:textSize="20sp"/>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart_v_LineChart"
android:layout_width="match_parent"
android:layout_height="300dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="@drawable/spacer_medium8"
android:showDividers="middle"
android:padding="5dp">
<TextView
android:id="@+id/chart_btn_lc_changeTheVerValue"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:background="@color/btn_gray"
android:text="是否显示顶点值"
android:textSize="15sp"
android:textColor="@color/btn_black"/>
<TextView
android:id="@+id/chart_btn_lc_changeFilled"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:background="@color/btn_gray"
android:text="是否填充"
android:textSize="15sp"
android:textColor="@color/btn_black"/>
<TextView
android:id="@+id/chart_btn_lc_changeTheVerCircle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:background="@color/btn_gray"
android:text="是否显示圆点"
android:textSize="15sp"
android:textColor="@color/btn_black"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="@drawable/spacer_medium8"
android:showDividers="middle"
android:padding="5dp">
<TextView
android:id="@+id/chart_btn_lc_changeMode"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:background="@color/btn_gray"
android:text="切换立方"
android:textSize="15sp"
android:textColor="@color/btn_black"/>
<TextView
android:id="@+id/chart_btn_lc_animationX"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:background="@color/btn_gray"
android:text="x轴动画"