├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dzq │ │ └── chartdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dzq │ │ │ └── chartdemo │ │ │ ├── MainActivity.java │ │ │ ├── utils │ │ │ └── CommonUtils.java │ │ │ └── widget │ │ │ └── DzqLineChart.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── icon_chart_dot.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attr.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── dzq │ └── chartdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img1.png ├── img2.png ├── img3.png ├── img4.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LineChartDemo 2 | android自定义控件-折线图,绝对呕心沥血之作!!! 3 | 可以显示多条折线,能够设置的功能有:图表背景色;标题字体的大小, 4 | 颜色;XY轴的颜色、线的宽度,实线还是虚线;折线的颜色、宽度;数据点的图标, 5 | 不设置的话,默认红色圆点,可设置圆点半径;特定选中Y轴内部线的 颜色、宽度。。。其他功能详见代码 6 | 7 | private float textSize = 20;// X、Y轴 字体大小 默认 20px 8 | private int textColor = Color.BLACK;// X、Y轴 字体颜色 默认黑色 Color.BLACK 9 | 10 | private int numberOfX = 6;// X轴 最多显示几个值 默认6个 11 | private int numberOfY = 8;// Y轴 最多显示几个值 默认8个 12 | 13 | private int paddingTop = 30;// View上边界距离 折线绘制区的 距离 14 | private int paddingLeft = 70;// View左边界距离 Y轴的 距离 15 | private int paddingRight = 50;// View右边界距离 折线绘制区的 距离 16 | private int paddingBottom = 50;// View下边界距离 X轴的 距离 17 | 18 | private int yTitle2RightPadding = 10;// Y 轴上标题距离右侧 内容区的距离 19 | 20 | private int appendXLength = 10;// 向左X轴突出的长度 21 | 22 | private int circleDotRadius = 10;//折线上圆点半径 默认10 23 | private int titleXRotateDegrees = 0;// X轴 标题 旋转角度 24 | private float xyAxisLineStrokeWidth = 2;// X、Y 轴 线宽度,(包括内部的X、Y 轴 线 ) 25 | 26 | private int selectedPositionInsideY = -1;// 选中的 内部Y轴 position, ( >=0 && < numberOfX &&绘制内部的Y轴完成) 才会绘制出来 27 | private int selectedPositionInsideYLineColor = Color.BLACK;//选中的 内部Y轴 的线颜色 默认黑色 Color.BLACK 28 | private float selectedPositionInsideYStrokeWidth = 2;// 选中的 内部Y轴线 宽度 29 | 30 | private int circleDotBitmapNotSet = Color.RED;//折线上圆点颜色 圆点Bitmap数组若不设置 圆点默认黑色 Color.RED 31 | private int lineColorNotSet = Color.BLACK;//折线颜色 若不设置 默认黑色 Color.BLACK 32 | private float lineChartStrokeWidth = 2;// 折线 宽度 33 | 34 | private int bgColor = Color.WHITE;// View 的背景色 默认白色 ffffff 35 | private int singleColumnFillColor = Color.rgb(Integer.parseInt("e7", 16), 36 | Integer.parseInt("e7", 16), Integer.parseInt("e9", 16));// 单数列的背景色 37 | private int doubleColumnFillColor = Color.rgb(Integer.parseInt("ea", 16), 38 | Integer.parseInt("e0", 16), Integer.parseInt("e8", 16));// 双数列的背景色 39 | private int fillDownColor = Color.rgb(Integer.parseInt("45", 16), 40 | Integer.parseInt("64", 16), Integer.parseInt("bf", 16));// 折线下方填充的颜色 注意 Alpha(50) 41 | private int xyAxisLineColor = Color.rgb(Integer.parseInt("74", 16), 42 | Integer.parseInt("6f", 16), Integer.parseInt("e3", 16));// X、Y 轴以及表格的线颜色 43 | 44 | private String yAxisUnit = "";// Y轴单位 45 | private int ScreenX;// View 宽度 46 | private int ScreenY;// View 高度 47 | private float maxNumber = 0;// Y轴最大值 48 | 49 | private List circleDotBitmapList;// 圆点Bitmap数组,每一条线一种圆点,若不设置 默认黑色圆点 Color.BLACK 50 | private List lineColorList;//折线颜色 数组,每一条线一种颜色,若不设置 默认黑色 Color.BLACK 51 | private List titleXList;// 传入的X轴标题 52 | private List titleYList;// 计算得出的Y轴标题 53 | private List> pointList;// 传入的数据 54 | 55 | private boolean isDrawYDashed = false;// 是否绘制Y轴 虚线 56 | private boolean isDrawY = true;// 是否绘制Y轴 57 | private boolean isDrawX = true;// 是否绘制X轴 58 | private boolean isDrawXDashed = false;// 是否绘制X轴 虚线 59 | 60 | private boolean isDrawInsideDashedY = true;// 是否绘制内部的Y轴 虚线 61 | private boolean isDrawInsedeY = true;// 是否绘制内部的Y轴 62 | private boolean isDrawInsideX = true;// 是否绘制内部的X轴 63 | private boolean isDrawInsideDashedX = true;// 是否绘制内部的X轴 虚线 64 | 65 | private boolean isColumnFillColor = false;// 是否填充单双列颜色 66 | 67 | private boolean isFillDown = true;// 是否填充点的下面部分 68 | private boolean isAppendX = false;// X轴是否向左突出一点 69 | 70 | 71 | ![image](https://github.com/dingzuoqiang/LineChartDemo/blob/master/img1.png) 72 | ![image](https://github.com/dingzuoqiang/LineChartDemo/blob/master/img2.png) 73 | ![image](https://github.com/dingzuoqiang/LineChartDemo/blob/master/img3.png) 74 | ![image](https://github.com/dingzuoqiang/LineChartDemo/blob/master/img4.png) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "26.0.0" 6 | defaultConfig { 7 | applicationId "com.dzq.chartdemo" 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | testCompile 'junit:junit:4.12' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/dzq/chartdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.dzq.chartdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.dzq.chartdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/dzq/chartdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dzq.chartdemo; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.dzq.chartdemo.widget.DzqLineChart; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Random; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | 15 | private List circleDotBitmapList;// 圆点Bitmap数组,每一条线一种圆点,若不设置 默认黑色圆点 Color.BLACK 16 | private List lineColorList;//折线颜色 数组,每一条线一种颜色,若不设置 默认黑色 Color.BLACK 17 | private List titleXList;// 传入的X轴标题 18 | private List> pointList;// 传入的数据 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | DzqLineChart dzqLineChart = (DzqLineChart) findViewById(R.id.lay_lineChart); 25 | DzqLineChart dzqLineChart2 = (DzqLineChart) findViewById(R.id.lay_lineChart2); 26 | 27 | pointList = new ArrayList>(); 28 | titleXList = new ArrayList(); 29 | lineColorList = new ArrayList(); 30 | lineColorList.add(Color.BLUE); 31 | circleDotBitmapList = new ArrayList<>(); 32 | circleDotBitmapList.add(R.mipmap.icon_chart_dot); 33 | 34 | for (int i = 0; i < 1; i++) { 35 | List pointInList = new ArrayList(); 36 | for (int j = 0; j < 5; j++) { 37 | Random r = new Random(); 38 | Float z = r.nextFloat() * 100; 39 | pointInList.add(z); 40 | titleXList.add("title" + (i + 1)); 41 | } 42 | pointList.add(pointInList); 43 | } 44 | 45 | // dzqLineChart.setBgColor(getResources().getColor(R.color.colorAccent)); 46 | dzqLineChart.setPointList(pointList); 47 | dzqLineChart.setTitleXList(titleXList); 48 | // dzqLineChart.setLineColorList(lineColorList); 49 | // dzqLineChart.setCircleDotBitmapList(circleDotBitmapList); 50 | // dzqLineChart.setSingleColumnFillColor(getResources().getColor(R.color.colorAccent)); 51 | 52 | dzqLineChart2.setPointList(pointList); 53 | dzqLineChart2.setTitleXList(titleXList); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/dzq/chartdemo/utils/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package com.dzq.chartdemo.utils; 2 | 3 | import android.graphics.Paint; 4 | import android.graphics.Rect; 5 | 6 | /** 7 | * Created by dingzuoqiang on 2017/10/15. 8 | * Email: 530858106@qq.com 9 | */ 10 | 11 | public class CommonUtils { 12 | 13 | public static int getTextWidth(String text, Paint paint) { 14 | Rect bounds = new Rect(); 15 | paint.getTextBounds(text, 0, text.length(), bounds); 16 | int width = bounds.left + bounds.width(); 17 | return width; 18 | } 19 | 20 | public static int getTextHeight(String text, Paint paint) { 21 | Rect bounds = new Rect(); 22 | paint.getTextBounds(text, 0, text.length(), bounds); 23 | int height = bounds.bottom + bounds.height(); 24 | return height; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/dzq/chartdemo/widget/DzqLineChart.java: -------------------------------------------------------------------------------- 1 | package com.dzq.chartdemo.widget; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.DashPathEffect; 11 | import android.graphics.Paint; 12 | import android.graphics.Path; 13 | import android.graphics.Point; 14 | import android.graphics.Rect; 15 | import android.text.TextUtils; 16 | import android.util.AttributeSet; 17 | import android.view.View; 18 | 19 | import com.dzq.chartdemo.R; 20 | import com.dzq.chartdemo.utils.CommonUtils; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * Created by dingzuoqiang on 2017/10/15. 27 | * Email: 530858106@qq.com 28 | */ 29 | 30 | public class DzqLineChart extends View { 31 | 32 | private float textSize = 20;// X、Y轴 字体大小 默认 20px 33 | private int textColor = Color.BLACK;// X、Y轴 字体颜色 默认黑色 Color.BLACK 34 | 35 | private int numberOfX = 6;// X轴 最多显示几个值 默认6个 36 | private int numberOfY = 8;// Y轴 最多显示几个值 默认8个 37 | 38 | private int paddingTop = 30;// View上边界距离 折线绘制区的 距离 39 | private int paddingLeft = 70;// View左边界距离 Y轴的 距离 40 | private int paddingRight = 50;// View右边界距离 折线绘制区的 距离 41 | private int paddingBottom = 50;// View下边界距离 X轴的 距离 42 | private int xTitlePaddingXAxis = 10;// X 轴标题到 X轴的 距离 43 | 44 | private int yTitle2RightPadding = 10;// Y 轴上标题距离右侧 内容区的距离 45 | 46 | private int appendXLength = 10;// 向左X轴突出的长度 47 | 48 | private int circleDotRadius = 10;//折线上圆点半径 默认10 49 | private int titleXRotateDegrees = 0;// X轴 标题 旋转角度 50 | private float xyAxisLineStrokeWidth = 2;// X、Y 轴 线宽度,(包括内部的X、Y 轴 线 ) 51 | 52 | private int selectedPositionInsideY = -1;// 选中的 内部Y轴 position, ( >=0 && < numberOfX &&绘制内部的Y轴完成) 才会绘制出来 53 | private int selectedPositionInsideYLineColor = Color.BLACK;//选中的 内部Y轴 的线颜色 默认黑色 Color.BLACK 54 | private float selectedPositionInsideYStrokeWidth = 2;// 选中的 内部Y轴线 宽度 55 | 56 | private int circleDotBitmapNotSet = Color.RED;//折线上圆点颜色 圆点Bitmap数组若不设置 圆点默认黑色 Color.RED 57 | private int lineColorNotSet = Color.BLACK;//折线颜色 若不设置 默认黑色 Color.BLACK 58 | private float lineChartStrokeWidth = 2;// 折线 宽度 59 | 60 | private int bgColor = Color.WHITE;// View 的背景色 默认白色 ffffff 61 | private int singleColumnFillColor = Color.rgb(Integer.parseInt("e7", 16), 62 | Integer.parseInt("e7", 16), Integer.parseInt("e9", 16));// 单数列的背景色 63 | private int doubleColumnFillColor = Color.rgb(Integer.parseInt("ea", 16), 64 | Integer.parseInt("e0", 16), Integer.parseInt("e8", 16));// 双数列的背景色 65 | private int fillDownColor = Color.rgb(Integer.parseInt("45", 16), 66 | Integer.parseInt("64", 16), Integer.parseInt("bf", 16));// 折线下方填充的颜色 注意 Alpha(50) 67 | private int xyAxisLineColor = Color.rgb(Integer.parseInt("74", 16), 68 | Integer.parseInt("6f", 16), Integer.parseInt("e3", 16));// X、Y 轴以及表格的线颜色 69 | 70 | private String yAxisUnit = "";// Y轴单位 71 | private int ScreenX;// View 宽度 72 | private int ScreenY;// View 高度 73 | private float maxNumber = 0;// Y轴最大值 74 | 75 | private List circleDotBitmapList;// 圆点Bitmap数组,每一条线一种圆点,若不设置 默认黑色圆点 Color.BLACK 76 | private List lineColorList;//折线颜色 数组,每一条线一种颜色,若不设置 默认黑色 Color.BLACK 77 | private List titleXList;// 传入的X轴标题 78 | private List titleYList;// 计算得出的Y轴标题 79 | private List> pointList;// 传入的数据 80 | 81 | private boolean isDrawYDashed = false;// 是否绘制Y轴 虚线 82 | private boolean isDrawY = true;// 是否绘制Y轴 83 | private boolean isDrawX = true;// 是否绘制X轴 84 | private boolean isDrawXDashed = false;// 是否绘制X轴 虚线 85 | 86 | private boolean isDrawInsideDashedY = true;// 是否绘制内部的Y轴 虚线 87 | private boolean isDrawInsedeY = true;// 是否绘制内部的Y轴 88 | private boolean isDrawInsideX = true;// 是否绘制内部的X轴 89 | private boolean isDrawInsideDashedX = true;// 是否绘制内部的X轴 虚线 90 | 91 | private boolean isColumnFillColor = false;// 是否填充单双列颜色 92 | 93 | private boolean isFillDown = true;// 是否填充点的下面部分 94 | private boolean isAppendX = false;// X轴是否向左突出一点 95 | 96 | private List> positionList;// 点坐标 97 | 98 | public DzqLineChart(Context context) { 99 | super(context); 100 | init(null, 0); 101 | } 102 | 103 | public DzqLineChart(Context context, AttributeSet attr) { 104 | super(context, attr); 105 | init(attr, 0); 106 | } 107 | 108 | public DzqLineChart(Context context, AttributeSet attrs, int defStyleAttr) { 109 | super(context, attrs, defStyleAttr); 110 | init(attrs, defStyleAttr); 111 | } 112 | 113 | private void init(AttributeSet attrs, int defStyle) { 114 | if (attrs == null) return; 115 | 116 | TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.DzqLineChart, defStyle, 0); 117 | isDrawX = array.getBoolean(R.styleable.DzqLineChart_isDrawX, isDrawX); 118 | isDrawY = array.getBoolean(R.styleable.DzqLineChart_isDrawY, isDrawY); 119 | isDrawXDashed = array.getBoolean(R.styleable.DzqLineChart_isDrawXDashed, isDrawXDashed); 120 | isDrawYDashed = array.getBoolean(R.styleable.DzqLineChart_isDrawYDashed, isDrawYDashed); 121 | isDrawInsideX = array.getBoolean(R.styleable.DzqLineChart_isDrawInsideX, isDrawInsideX); 122 | isDrawInsedeY = array.getBoolean(R.styleable.DzqLineChart_isDrawInsedeY, isDrawInsedeY); 123 | isDrawInsideDashedX = array.getBoolean(R.styleable.DzqLineChart_isDrawInsideDashedX, isDrawInsideDashedX); 124 | isDrawInsideDashedY = array.getBoolean(R.styleable.DzqLineChart_isDrawInsideDashedY, isDrawInsideDashedY); 125 | isColumnFillColor = array.getBoolean(R.styleable.DzqLineChart_isColumnFillColor, isColumnFillColor); 126 | isFillDown = array.getBoolean(R.styleable.DzqLineChart_isFillDown, isFillDown); 127 | isAppendX = array.getBoolean(R.styleable.DzqLineChart_isAppendX, isAppendX); 128 | 129 | textSize = array.getDimension(R.styleable.DzqLineChart_textSize, textSize); 130 | xyAxisLineStrokeWidth = array.getDimension(R.styleable.DzqLineChart_xyAxisLineStrokeWidth, xyAxisLineStrokeWidth); 131 | lineChartStrokeWidth = array.getDimension(R.styleable.DzqLineChart_lineChartStrokeWidth, lineChartStrokeWidth); 132 | 133 | textColor = array.getColor(R.styleable.DzqLineChart_textColor, textColor); 134 | bgColor = array.getColor(R.styleable.DzqLineChart_bgColor, bgColor); 135 | xyAxisLineColor = array.getColor(R.styleable.DzqLineChart_xyAxisLineColor, xyAxisLineColor); 136 | 137 | selectedPositionInsideY = array.getInt(R.styleable.DzqLineChart_selectedPositionInsideY, selectedPositionInsideY); 138 | selectedPositionInsideYLineColor = array.getColor(R.styleable.DzqLineChart_selectedPositionInsideYLineColor, selectedPositionInsideYLineColor); 139 | selectedPositionInsideYStrokeWidth = array.getDimension(R.styleable.DzqLineChart_selectedPositionInsideYStrokeWidth, selectedPositionInsideYStrokeWidth); 140 | 141 | array.recycle(); 142 | 143 | } 144 | 145 | /** 146 | * 计算得出View的宽高 147 | * 148 | * @param widthMeasureSpec 149 | * @param heightMeasureSpec 150 | */ 151 | @Override 152 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 153 | 154 | int measuredHeight = measureHeight(heightMeasureSpec); 155 | 156 | int measuredWidth = measureWidth(widthMeasureSpec); 157 | 158 | setMeasuredDimension(measuredWidth, measuredHeight); 159 | 160 | ScreenX = measuredWidth; 161 | 162 | ScreenY = measuredHeight; 163 | 164 | } 165 | 166 | private int measureHeight(int measureSpec) { 167 | 168 | int specMode = MeasureSpec.getMode(measureSpec); 169 | int specSize = MeasureSpec.getSize(measureSpec); 170 | 171 | int result = 300; 172 | if (specMode == MeasureSpec.AT_MOST) { 173 | 174 | result = specSize; 175 | } else if (specMode == MeasureSpec.EXACTLY) { 176 | 177 | result = specSize; 178 | } 179 | 180 | return result; 181 | } 182 | 183 | private int measureWidth(int measureSpec) { 184 | int specMode = MeasureSpec.getMode(measureSpec); 185 | int specSize = MeasureSpec.getSize(measureSpec); 186 | 187 | int result = 450; 188 | if (specMode == MeasureSpec.AT_MOST) { 189 | result = specSize; 190 | } else if (specMode == MeasureSpec.EXACTLY) { 191 | 192 | result = specSize; 193 | } 194 | 195 | return result; 196 | } 197 | 198 | /** 199 | * 绘画View方法 200 | * 201 | * @param canvas 202 | */ 203 | @SuppressLint("DrawAllocation") 204 | @Override 205 | protected void onDraw(Canvas canvas) { 206 | super.onDraw(canvas); 207 | maxNumber = 0; 208 | List listX = initNumberOfX();// 计算出X轴平均后的坐标 209 | List listY = initNumberOfY();// 计算出Y轴平均后的坐标 210 | canvas.drawColor(bgColor);// 背景色 211 | fillColorToColumn(listX, canvas);// 对每一列 填充颜色 212 | 213 | drawXyAxis(canvas, listX, listY); 214 | setXTitle(listX, canvas);// 画折线图X的单位 215 | setYTitle(listY, canvas);// 画折线图Y的单位,同时计算出最大的Y轴值 216 | 217 | positionList = countListPosition(listX);// 计算像素位置 218 | drawFill(canvas, positionList);// 填充折线和边框 219 | drawLineChart(canvas, positionList);// 画折线 220 | drawCicle(canvas, positionList);// 画点 221 | 222 | } 223 | 224 | // 计算像素位置 225 | private List> countListPosition(List listX) { 226 | List> positionList = new ArrayList>(); 227 | if (pointList != null) { 228 | for (int i = 0; i < pointList.size(); i++) { 229 | List positionInList = new ArrayList(); 230 | for (int j = 0; !isIndexOutOfBounds(j) && j < pointList.get(i).size(); j++) { 231 | Point point = new Point(); 232 | Float z = pointList.get(i).get(j); 233 | point.x = listX.get(j).x; 234 | point.y = listX.get(j).y + paddingTop 235 | - (int) ((listX.get(j).y) * (float) z / (float) maxNumber); 236 | positionInList.add(point); 237 | } 238 | positionList.add(positionInList); 239 | } 240 | } 241 | return positionList; 242 | } 243 | 244 | // 判断 显示的点数据有没有超出 X、Y 轴 的最大显示数 245 | private boolean isIndexOutOfBounds(int index) { 246 | return index >= numberOfX || index >= numberOfY; 247 | } 248 | 249 | 250 | //对单双列做不同的填充颜色 251 | private void fillColorToColumn(List listX, Canvas canvas) { 252 | if (isColumnFillColor) { 253 | Paint paint = new Paint(); 254 | paint.setStyle(Paint.Style.FILL); 255 | for (int i = 0; i < numberOfX - 1; i++) { 256 | if (i % 2 == 0) { 257 | paint.setColor(singleColumnFillColor); 258 | } else { 259 | paint.setColor(doubleColumnFillColor); 260 | } 261 | canvas.drawRect(listX.get(i).x, paddingTop, listX.get(i + 1).x, ScreenY - paddingBottom, 262 | paint); 263 | } 264 | } 265 | } 266 | 267 | // 绘制 XY 轴,以及 内部 表格线 268 | private void drawXyAxis(Canvas canvas, List listX, List listY) { 269 | if (canvas == null || listX == null || listX.size() == 0 || listY == null || listY.size() == 0) 270 | return; 271 | Paint paint = new Paint(); 272 | paint.setColor(xyAxisLineColor);// //表格线颜色 273 | paint.setStrokeWidth(xyAxisLineStrokeWidth); 274 | 275 | if (isDrawX) {//是否绘制X轴 276 | int appendX = 0; 277 | if (isAppendX) { 278 | appendX = appendXLength; 279 | } 280 | if (isDrawXDashed) { 281 | paintDashed(canvas, paddingLeft - appendX, paddingTop + listY.get(0).y, listY.get(0).x 282 | + paddingLeft, 283 | paddingTop + listY.get(0).y, xyAxisLineColor); 284 | } else 285 | canvas.drawLine(paddingLeft - appendX, paddingTop + listY.get(0).y, listY.get(0).x 286 | + paddingLeft, 287 | paddingTop + listY.get(0).y, paint); 288 | } 289 | if (isDrawY) {//是否绘制Y轴 290 | if (isDrawYDashed) { 291 | paintDashed(canvas, listX.get(0).x, paddingTop, listX.get(0).x, listX.get(0).y + paddingTop, xyAxisLineColor); 292 | } else 293 | canvas.drawLine(listX.get(0).x, paddingTop, listX.get(0).x, listX.get(0).y + paddingTop, paint); 294 | } 295 | 296 | if (isDrawInsedeY) {// 是否绘制内部的Y轴 297 | for (int i = 0; i < listX.size(); i++) {// 第一根内部 y轴线 和 Y轴线 重叠,故绘制Y轴的时候 不绘制第一条线 298 | if (isDrawY && i == 0) continue; 299 | Point point = listX.get(i); 300 | if (isDrawInsideDashedY) { 301 | paintDashed(canvas, point.x, paddingTop, point.x, point.y + paddingTop, xyAxisLineColor); 302 | } else { 303 | canvas.drawLine(point.x, paddingTop, point.x, point.y + paddingTop, paint); 304 | } 305 | 306 | } 307 | } 308 | if (isDrawInsideX) {// 是否绘制内部的X轴 309 | 310 | int appendX = 0; 311 | if (isAppendX) { 312 | appendX = appendXLength; 313 | } 314 | for (int i = (isDrawX ? 1 : 0); i < listY.size(); i++) {// 第一根内部 x轴线 和 X轴线 重叠,故绘制X轴的时候 不绘制第一条线 315 | Point point = listY.get(i); 316 | if (isDrawInsideDashedX) { 317 | paintDashed(canvas, paddingLeft - appendX, paddingTop + point.y, point.x + paddingLeft, 318 | paddingTop + point.y, xyAxisLineColor); 319 | } else { 320 | canvas.drawLine(paddingLeft - appendX, paddingTop + point.y, point.x + paddingLeft, 321 | paddingTop + point.y, paint); 322 | } 323 | 324 | } 325 | 326 | } 327 | 328 | // 选中的 内部Y轴 position, (selectedPositionInsideY >=0 && < numberOfX &&绘制内部的Y轴完成) 才会绘制出来 329 | paint.setColor(selectedPositionInsideYLineColor);// //表格线颜色 330 | paint.setStrokeWidth(selectedPositionInsideYStrokeWidth); 331 | if (selectedPositionInsideY >= 0 && selectedPositionInsideY < listX.size()) { 332 | Point point = listX.get(selectedPositionInsideY); 333 | canvas.drawLine(point.x, paddingTop, point.x, point.y + paddingTop, paint); 334 | } 335 | 336 | } 337 | 338 | /** 339 | * 为X轴每个标题 340 | *

341 | * canvas.drawText(text, x, y, paint),第一个参数是我们需要绘制的文本,第四个参数是我们的画笔, 342 | * 这两个不用多说,主要是第二和第三个参数的含义,这两个参数在不同的情况下的值还是不一样的, 343 | * x默认是这个字符串的左边在屏幕的位置,如果设置了paint.setTextAlign(Paint.Align.CENTER);那就是字符的中心, 344 | * y是指定这个字符baseline在屏幕上的位置,大家记住了,不要混淆,y不是这个字符中心在屏幕上的位置,而是baseline在屏幕上的位置。 345 | */ 346 | private void setXTitle(List listX, Canvas canvas) { 347 | Paint paint = new Paint(); 348 | paint.setColor(textColor); 349 | paint.setTextSize(textSize); 350 | 351 | if (titleXList == null) { 352 | titleXList = new ArrayList(); 353 | for (int i = 1; i <= numberOfX; i++) { 354 | titleXList.add("title" + i); 355 | } 356 | } 357 | for (int i = 0; i < numberOfX && i < titleXList.size(); i++) { 358 | canvas.save(); 359 | String xTitle = titleXList.get(i); 360 | if (xTitle != null) { 361 | int titleHeight = CommonUtils.getTextHeight(xTitle, paint); 362 | int finalX = listX.get(i).x; 363 | if (i != 0) 364 | finalX = finalX - CommonUtils.getTextWidth(xTitle, paint) / 2; 365 | canvas.rotate(titleXRotateDegrees, finalX, 366 | listX.get(i).y + paddingTop + xTitlePaddingXAxis + titleHeight); 367 | canvas.drawText(titleXList.get(i), finalX, 368 | listX.get(i).y + paddingTop + xTitlePaddingXAxis + titleHeight 369 | , paint); 370 | canvas.restore(); 371 | } 372 | } 373 | } 374 | 375 | //为Y轴找到最大值以及它的每个标题 376 | private void setYTitle(List listY, Canvas canvas) { 377 | Paint paint = new Paint(); 378 | paint.setColor(textColor); 379 | paint.setTextSize(textSize); 380 | if (pointList == null) { 381 | titleYList = new ArrayList(); 382 | for (int i = 1; i <= numberOfY; i++) { 383 | titleYList.add(0, String.valueOf(100 / i)); 384 | } 385 | } else { 386 | for (int i = 0; i < pointList.size(); i++) { 387 | for (int j = 0; j < pointList.get(i).size(); j++) { 388 | 389 | if (pointList.get(i).get(j) > maxNumber) { 390 | maxNumber = pointList.get(i).get(j); 391 | } 392 | } 393 | } 394 | maxNumber = maxNumber + maxNumber / 3; 395 | titleYList = new ArrayList(); 396 | for (int i = 0; i < numberOfY; i++) { 397 | titleYList.add(String.valueOf((int) (0 + i * (maxNumber / (numberOfY - 1))))); 398 | } 399 | } 400 | 401 | int finalAppendX = (isAppendX && appendXLength > 0) ? appendXLength : 0; 402 | finalAppendX = finalAppendX + yTitle2RightPadding; 403 | 404 | for (int i = 0; i < numberOfY; i++) { 405 | String title = titleYList.get(i); 406 | if (!TextUtils.isEmpty(title)) { 407 | if (i == 0) 408 | title = title + yAxisUnit; 409 | Rect bounds = new Rect(); 410 | paint.getTextBounds(title, 0, title.length(), bounds); 411 | canvas.drawText(titleYList.get(i), paddingLeft - finalAppendX - CommonUtils.getTextWidth(title, paint), 412 | paddingTop 413 | + listY.get(i).y + CommonUtils.getTextHeight(title, paint) / 2, paint); 414 | 415 | } 416 | 417 | } 418 | } 419 | 420 | 421 | // 填充折线和边框 422 | private void drawFill(Canvas canvas, List> positionList) { 423 | if (!isFillDown || positionList == null) { 424 | return; 425 | } 426 | Paint paint = new Paint(); 427 | paint.setAntiAlias(true); 428 | paint.setColor(fillDownColor); 429 | paint.setAlpha(50); 430 | for (int i = 0; i < positionList.size(); i++) { 431 | Path path = new Path(); 432 | path.moveTo(paddingLeft, ScreenY - paddingBottom); 433 | int size = positionList.get(i).size(); 434 | for (int j = 0; j < size; j++) { 435 | path.lineTo(positionList.get(i).get(j).x, positionList.get(i).get(j).y); 436 | } 437 | if (size > 0) 438 | path.lineTo(positionList.get(i).get(size - 1).x, ScreenY - paddingBottom); 439 | path.close(); 440 | canvas.drawPath(path, paint); 441 | } 442 | } 443 | 444 | // 画折线 445 | private void drawLineChart(Canvas canvas, List> positionList) { 446 | if (positionList == null) return; 447 | Paint paint = new Paint(); 448 | paint.setAntiAlias(true); 449 | paint.setStrokeWidth(lineChartStrokeWidth); 450 | 451 | for (int i = 0; i < positionList.size(); i++) { 452 | if (lineColorList != null && lineColorList.size() - 1 >= i && lineColorList.get(i) != null) { 453 | paint.setColor(lineColorList.get(i)); 454 | } else { 455 | paint.setColor(lineColorNotSet); 456 | } 457 | for (int j = 0; j < positionList.get(i).size() - 1; j++) { 458 | canvas.drawLine(positionList.get(i).get(j).x, positionList.get(i).get(j).y, 459 | positionList.get(i).get(j + 1).x, positionList.get(i).get(j + 1).y, paint); 460 | } 461 | } 462 | } 463 | 464 | // 画点 465 | private void drawCicle(Canvas canvas, List> positionList) { 466 | if (positionList == null) return; 467 | Paint paint = new Paint(); 468 | paint.setAntiAlias(true);//设置画笔为无锯齿 469 | paint.setColor(circleDotBitmapNotSet);//设置画笔颜色 470 | for (int i = 0; i < positionList.size(); i++) { 471 | Bitmap bitmap = null; 472 | if (circleDotBitmapList != null && circleDotBitmapList.size() - 1 >= i && circleDotBitmapList.get(i) != null) { 473 | int resouceId = circleDotBitmapList.get(i); 474 | bitmap = BitmapFactory.decodeResource(getResources(), resouceId); 475 | } 476 | 477 | for (int j = 0; j < positionList.get(i).size(); j++) { 478 | if (bitmap != null) { 479 | canvas.drawBitmap(bitmap, positionList.get(i).get(j).x + 0.5f - bitmap.getWidth() 480 | / 2, 481 | positionList.get(i).get(j).y + 0.5f - bitmap.getHeight() / 2, paint); 482 | } else { 483 | canvas.drawCircle(positionList.get(i).get(j).x, positionList.get(i).get(j).y, 484 | circleDotRadius, paint); 485 | } 486 | } 487 | 488 | } 489 | } 490 | 491 | // 计算出X轴平均后的坐标 492 | private List initNumberOfX() { 493 | int num = (ScreenX - paddingLeft - paddingRight) / (numberOfX - 1); 494 | List list = new ArrayList(); 495 | for (int i = 0; i < numberOfX; i++) { 496 | Point point = new Point(); 497 | point.y = ScreenY - paddingBottom - paddingTop; 498 | point.x = paddingLeft + num * i; 499 | list.add(point); 500 | } 501 | return list; 502 | } 503 | 504 | // 计算出Y轴平均后的坐标 505 | private List initNumberOfY() { 506 | int num = (ScreenY - paddingBottom - paddingTop) / (numberOfY - 1); 507 | List list = new ArrayList(); 508 | for (int i = 0; i < numberOfY; i++) { 509 | Point point = new Point(); 510 | point.x = ScreenX - paddingLeft - paddingRight; 511 | point.y = ScreenY - paddingBottom - paddingTop - num * i; 512 | list.add(point); 513 | } 514 | return list; 515 | } 516 | 517 | /** 518 | * 画虚线 519 | * 520 | * @param canvas 521 | * @param moveToX 522 | * @param moveToY 523 | * @param lineToX 524 | * @param lineToY 525 | */ 526 | private void paintDashed(Canvas canvas, int moveToX, int moveToY, int lineToX, int lineToY, int color) { 527 | DashPathEffect pathEffect = new DashPathEffect(new float[]{6, 4}, 0); 528 | Paint paint = new Paint(); 529 | paint.reset(); 530 | paint.setStyle(Paint.Style.STROKE); 531 | paint.setStrokeWidth(xyAxisLineStrokeWidth); 532 | paint.setColor(color); 533 | paint.setAntiAlias(true); 534 | paint.setPathEffect(pathEffect); 535 | Path path = new Path(); 536 | path.moveTo(moveToX, moveToY); 537 | path.lineTo(lineToX, lineToY); 538 | canvas.drawPath(path, paint); 539 | } 540 | 541 | public void setTextSize(float textSize) { 542 | this.textSize = textSize; 543 | } 544 | 545 | public void setTextColor(int textColor) { 546 | this.textColor = textColor; 547 | } 548 | 549 | public void setNumberOfX(int numberOfX) { 550 | this.numberOfX = numberOfX; 551 | } 552 | 553 | public void setNumberOfY(int numberOfY) { 554 | this.numberOfY = numberOfY; 555 | } 556 | 557 | public void setPaddingTop(int paddingTop) { 558 | this.paddingTop = paddingTop; 559 | } 560 | 561 | public void setPaddingLeft(int paddingLeft) { 562 | this.paddingLeft = paddingLeft; 563 | } 564 | 565 | public void setPaddingRight(int paddingRight) { 566 | this.paddingRight = paddingRight; 567 | } 568 | 569 | public void setPaddingBottom(int paddingBottom) { 570 | this.paddingBottom = paddingBottom; 571 | } 572 | 573 | public void setyTitle2RightPadding(int yTitle2RightPadding) { 574 | this.yTitle2RightPadding = yTitle2RightPadding; 575 | } 576 | 577 | public void setAppendXLength(int appendXLength) { 578 | this.appendXLength = appendXLength; 579 | } 580 | 581 | public void setCircleDotRadius(int circleDotRadius) { 582 | this.circleDotRadius = circleDotRadius; 583 | } 584 | 585 | public void setTitleXRotateDegrees(int titleXRotateDegrees) { 586 | this.titleXRotateDegrees = titleXRotateDegrees; 587 | } 588 | 589 | public void setXyAxisLineStrokeWidth(float xyAxisLineStrokeWidth) { 590 | this.xyAxisLineStrokeWidth = xyAxisLineStrokeWidth; 591 | } 592 | 593 | public void setSelectedPositionInsideY(int selectedPositionInsideY) { 594 | this.selectedPositionInsideY = selectedPositionInsideY; 595 | } 596 | 597 | public void setSelectedPositionInsideYLineColor(int selectedPositionInsideYLineColor) { 598 | this.selectedPositionInsideYLineColor = selectedPositionInsideYLineColor; 599 | } 600 | 601 | public void setSelectedPositionInsideYStrokeWidth(float selectedPositionInsideYStrokeWidth) { 602 | this.selectedPositionInsideYStrokeWidth = selectedPositionInsideYStrokeWidth; 603 | } 604 | 605 | public void setCircleDotBitmapNotSet(int circleDotBitmapNotSet) { 606 | this.circleDotBitmapNotSet = circleDotBitmapNotSet; 607 | } 608 | 609 | public void setLineColorNotSet(int lineColorNotSet) { 610 | this.lineColorNotSet = lineColorNotSet; 611 | } 612 | 613 | public void setLineChartStrokeWidth(float lineChartStrokeWidth) { 614 | this.lineChartStrokeWidth = lineChartStrokeWidth; 615 | } 616 | 617 | public void setBgColor(int bgColor) { 618 | this.bgColor = bgColor; 619 | } 620 | 621 | public void setSingleColumnFillColor(int singleColumnFillColor) { 622 | this.singleColumnFillColor = singleColumnFillColor; 623 | } 624 | 625 | public void setDoubleColumnFillColor(int doubleColumnFillColor) { 626 | this.doubleColumnFillColor = doubleColumnFillColor; 627 | } 628 | 629 | public void setFillDownColor(int fillDownColor) { 630 | this.fillDownColor = fillDownColor; 631 | } 632 | 633 | public void setXyAxisLineColor(int xyAxisLineColor) { 634 | this.xyAxisLineColor = xyAxisLineColor; 635 | } 636 | 637 | public void setyAxisUnit(String yAxisUnit) { 638 | this.yAxisUnit = yAxisUnit; 639 | } 640 | 641 | public void setCircleDotBitmapList(List circleDotBitmapList) { 642 | this.circleDotBitmapList = circleDotBitmapList; 643 | } 644 | 645 | public void setLineColorList(List lineColorList) { 646 | this.lineColorList = lineColorList; 647 | } 648 | 649 | public void setTitleXList(List titleXList) { 650 | this.titleXList = titleXList; 651 | } 652 | 653 | public void setPointList(List> pointList) { 654 | this.pointList = pointList; 655 | } 656 | 657 | public void setDrawYDashed(boolean drawYDashed) { 658 | isDrawYDashed = drawYDashed; 659 | } 660 | 661 | public void setDrawY(boolean drawY) { 662 | isDrawY = drawY; 663 | } 664 | 665 | public void setDrawX(boolean drawX) { 666 | isDrawX = drawX; 667 | } 668 | 669 | public void setDrawXDashed(boolean drawXDashed) { 670 | isDrawXDashed = drawXDashed; 671 | } 672 | 673 | public void setDrawInsideDashedY(boolean drawInsideDashedY) { 674 | isDrawInsideDashedY = drawInsideDashedY; 675 | } 676 | 677 | public void setDrawInsedeY(boolean drawInsedeY) { 678 | isDrawInsedeY = drawInsedeY; 679 | } 680 | 681 | public void setDrawInsideX(boolean drawInsideX) { 682 | isDrawInsideX = drawInsideX; 683 | } 684 | 685 | public void setDrawInsideDashedX(boolean drawInsideDashedX) { 686 | isDrawInsideDashedX = drawInsideDashedX; 687 | } 688 | 689 | public void setColumnFillColor(boolean columnFillColor) { 690 | isColumnFillColor = columnFillColor; 691 | } 692 | 693 | public void setFillDown(boolean fillDown) { 694 | isFillDown = fillDown; 695 | } 696 | 697 | public void setAppendX(boolean appendX) { 698 | isAppendX = appendX; 699 | } 700 | 701 | public List> getPositionList() { 702 | return positionList; 703 | } 704 | 705 | public int getPaddingBottom() { 706 | return paddingBottom; 707 | } 708 | 709 | public int getPaddingTop() { 710 | return paddingTop; 711 | } 712 | 713 | public int getPaddingLeft() { 714 | return paddingLeft; 715 | } 716 | 717 | public int getPaddingRight() { 718 | return paddingRight; 719 | } 720 | 721 | public int getScreenX() { 722 | return ScreenX; 723 | } 724 | 725 | public int getScreenY() { 726 | return ScreenY; 727 | } 728 | 729 | public void setxTitlePaddingXAxis(int xTitlePaddingXAxis) { 730 | this.xTitlePaddingXAxis = xTitlePaddingXAxis; 731 | } 732 | } 733 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 35 | 36 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/icon_chart_dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/app/src/main/res/mipmap-xxhdpi/icon_chart_dot.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ChartDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/dzq/chartdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.dzq.chartdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/img1.png -------------------------------------------------------------------------------- /img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/img2.png -------------------------------------------------------------------------------- /img3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/img3.png -------------------------------------------------------------------------------- /img4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dingzuoqiang/LineChartDemo/44f704f25fe67d29ef2f5a2f7353a1b860ea0c15/img4.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------