MyChartView.java是自定义图表
将MyChartView.java添加到工程,可以和main放在同一个包
基本步骤
1、初始化ui
2、初始化图表
(1)设置图表的数据集,最大值,平均值,x轴单位,y轴单位,是否显示y轴线
(2)设置顶部和底部的距离
(3)设置曲线风格
3、数据集数据有更新时使用invalidate();方法更新ui
xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- 自定义view需要写全路径 -->
<com.example.mychartdemo.MyChartView
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_he