├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ └── httplib-release.aar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── chartview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── chartview │ │ │ ├── FllowerViewActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── bean │ │ │ └── Fllower.java │ │ │ ├── fragment │ │ │ ├── BarChartFragment.java │ │ │ ├── CurveChartFragment.java │ │ │ ├── CustomizedBloodChartFragment.java │ │ │ ├── HistogramBarChartFragment.java │ │ │ ├── LineChartFragment.java │ │ │ ├── SportBarChartFragment.java │ │ │ └── StackBarChartFragment.java │ │ │ └── view │ │ │ ├── FllowerAnimation.java │ │ │ └── MyView.java │ └── res │ │ ├── drawable │ │ ├── exchange_icon.png │ │ └── round_white_alpha.xml │ │ ├── layout │ │ ├── activity_fllower_view.xml │ │ ├── activity_main.xml │ │ ├── fragment_barchart.xml │ │ ├── fragment_cbarchart.xml │ │ ├── fragment_curvechart.xml │ │ ├── fragment_hbarchart.xml │ │ ├── fragment_linechart.xml │ │ ├── fragment_sportchart.xml │ │ └── fragment_stack_bar_chart.xml │ │ ├── mipmap-hdpi │ │ ├── app_icon.png │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── app_icon.png │ │ ├── chart_view_icon.png │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── app_icon.png │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── chartview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── 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 | /chartlib 11 | /chart 12 | -------------------------------------------------------------------------------- /.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/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 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | >前言:最近公司这边项目新版本界面大改动,以前版本都是使用MPAndroidChart来实现的图表,这次UI界面需求设计个性化比较强,只好把以前所有的图表重新设计实现一遍,花了一天分析设计结构及抽取共用模块,一天实现图表的数据填充及图表效果绘制,一天优化图表代码及图表行为属性暴露。如下图,图表的使用样例已经上传到github,有需要的朋友可以借鉴。 2 | 3 | >体验apk:[https://fir.im/6sf2](https://fir.im/6sf2) 4 | github图表使用演示地址:[https://github.com/huangweicai/chart](https://github.com/huangweicai/chart) 5 | 快捷使用:compile 'me.hwc:chart :1.0.1' 6 | 7 | >欢迎关注oklib,后面图表的所有源码都会集成到oklib库中[http://www.jianshu.com/p/87e7392a16ff](http://www.jianshu.com/p/87e7392a16ff) 8 | 9 | ![图表演示](http://upload-images.jianshu.io/upload_images/2405826-a7f4ff06d39a39c1.GIF?imageMogr2/auto-orient/strip) 10 | 11 | 12 | #####折线图: 13 | ``` 14 | public class LineChartFragment extends Fragment { 15 | private LineChartView chartView1; 16 | private LineChartView chartView2; 17 | private LineChartView chartView3; 18 | private LineChartView chartView4; 19 | 20 | @Nullable 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 23 | View view = inflater.inflate(R.layout.fragment_weight_chart, null, false); 24 | chartView1 = (LineChartView) view.findViewById(R.id.weightChart1); 25 | chartView2 = (LineChartView) view.findViewById(R.id.weightChart2); 26 | chartView3 = (LineChartView) view.findViewById(R.id.weightChart3); 27 | chartView4 = (LineChartView) view.findViewById(R.id.weightChart4); 28 | return view; 29 | } 30 | 31 | public void showChart() { 32 | //注意:图表使用一定要延迟使用 33 | new Handler().postDelayed(new Runnable() { 34 | @Override 35 | public void run() { 36 | chartView1 37 | .setLineColor(0xffff0000) 38 | .setTextColor(0xff0000ff) 39 | .setCircleColor(0xff00ff00) 40 | .setTextSize(24) 41 | .setCircleRadiusSize(14) 42 | .setLineSize(10)//以上子类内容,必须写在下面方法上面 43 | .isShowDatumLine_X(false) 44 | .isShowDatumLine_Y(false) 45 | .setType(BaseChartView.DAY) 46 | .setYMaxValue(150) 47 | .setUnitValueText("Kg") 48 | .refreshData(getDayData()); 49 | chartView2 50 | .isShowDatumLine_X(false) 51 | .isShowDatumLine_Y(false) 52 | .setType(BaseChartView.WEEK) 53 | .setYMaxValue(150) 54 | .setUnitValueText("Kg") 55 | .refreshData(getWeekData()); 56 | chartView3 57 | .isShowDatumLine_X(false) 58 | .isShowDatumLine_Y(false) 59 | .setType(BaseChartView.MONTH) 60 | .setYMaxValue(150) 61 | .setUnitValueText("Kg") 62 | .refreshData(getMonthData()); 63 | chartView4 64 | .isShowDatumLine_X(false) 65 | .isShowDatumLine_Y(false) 66 | .setType(BaseChartView.YEAR) 67 | .setYMaxValue(150) 68 | .setUnitValueText("Kg") 69 | .refreshData(getYearData()); 70 | } 71 | }, 800); 72 | } 73 | 74 | private List getDayData() { 75 | //日数据源 76 | List datas1 = new ArrayList<>(); 77 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 60f)); 78 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 122f)); 79 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 86f)); 80 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 108f)); 81 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 92f)); 82 | datas1.add(new BaseChartView.DataBean("20170804 241700", 92f)); 83 | return datas1; 84 | } 85 | 86 | private List getWeekData() { 87 | //周数据源 88 | List datas2 = new ArrayList<>(); 89 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 60f)); 90 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 86f)); 91 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 86f)); 92 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 68f)); 93 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 72f)); 94 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 112f)); 95 | return datas2; 96 | } 97 | 98 | private List getMonthData() { 99 | //月数据源 100 | List datas3 = new ArrayList<>(); 101 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 60f)); 102 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 116f)); 103 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 98f)); 104 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 52f)); 105 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 102f)); 106 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 82f)); 107 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 132f)); 108 | return datas3; 109 | } 110 | 111 | private List getYearData() { 112 | //年数据源 113 | List datas4 = new ArrayList<>(); 114 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 60f)); 115 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 116f)); 116 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 86f)); 117 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 72f)); 118 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 122f)); 119 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 82f)); 120 | return datas4; 121 | } 122 | } 123 | ``` 124 | ``` 125 | 126 | 131 | 132 | 135 | 136 | 140 | 141 | 145 | 146 | 154 | 155 | 159 | 160 | 168 | 169 | 173 | 174 | 182 | 183 | 187 | 188 | 196 | 197 | 198 | 199 | 200 | 201 | ``` 202 | 203 | #####曲线图: 204 | ``` 205 | public class CurveChartFragment extends Fragment { 206 | private CurveChartView chartView1; 207 | private CurveChartView chartView2; 208 | private CurveChartView chartView3; 209 | private CurveChartView chartView4; 210 | 211 | @Nullable 212 | @Override 213 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 214 | View view = inflater.inflate(R.layout.fragment_rate_chart, null, false); 215 | chartView1 = (CurveChartView) view.findViewById(R.id.weightChart1); 216 | chartView2 = (CurveChartView) view.findViewById(R.id.weightChart2); 217 | chartView3 = (CurveChartView) view.findViewById(R.id.weightChart3); 218 | chartView4 = (CurveChartView) view.findViewById(R.id.weightChart4); 219 | return view; 220 | } 221 | 222 | public void showChart() { 223 | new Handler().postDelayed(new Runnable() { 224 | @Override 225 | public void run() { 226 | chartView1 227 | .seMaxLineColor(0xffff0000) 228 | .setMaxTextColor(0xffff0000) 229 | .setAvgLineColor(0xff00ff00) 230 | .setAvgTextColor(0xff00ff00) 231 | .setMinLineColor(0xff0000ff) 232 | .setMinTextColor(0xff0000ff) 233 | .setLineWidht(10)//以上子类内容,必须写在下面方法上面 234 | .isShowDatumLine_X(false) 235 | .isShowDatumLine_Y(false) 236 | .setType(BaseChartView.DAY) 237 | .setYMaxValue(220) 238 | .setUnitValueText("bpm") 239 | .refreshData(getDayData()); 240 | chartView2 241 | .isShowDatumLine_X(false) 242 | .isShowDatumLine_Y(false) 243 | .setType(BaseChartView.WEEK) 244 | .setYMaxValue(220) 245 | .setUnitValueText("bpm") 246 | .refreshData(getWeekData()); 247 | chartView3 248 | .isShowDatumLine_X(false) 249 | .isShowDatumLine_Y(false) 250 | .setType(BaseChartView.MONTH) 251 | .setYMaxValue(220) 252 | .setUnitValueText("bpm") 253 | .refreshData(getMonthData()); 254 | chartView4 255 | .isShowDatumLine_X(false) 256 | .isShowDatumLine_Y(false) 257 | .setType(BaseChartView.YEAR) 258 | .setYMaxValue(220) 259 | .setUnitValueText("bpm") 260 | .refreshData(getYearData()); 261 | } 262 | }, 800); 263 | } 264 | 265 | private List getDayData() { 266 | //日数据源 267 | List datas1 = new ArrayList<>(); 268 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 80f, 64f, 40f)); 269 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 122f, 98f, 70f)); 270 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 86f, 58f, 30f)); 271 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 108f, 88f, 67f)); 272 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 92f, 78f, 50f)); 273 | return datas1; 274 | } 275 | 276 | private List getWeekData() { 277 | //周数据源 278 | List datas2 = new ArrayList<>(); 279 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 80f, 64f, 40f)); 280 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 122f, 98f, 70f)); 281 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 86f, 58f, 30f)); 282 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 108f, 88f, 67f)); 283 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 92f, 78f, 50f)); 284 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 112f, 98f, 80f)); 285 | return datas2; 286 | } 287 | 288 | private List getMonthData() { 289 | //月数据源 290 | List datas3 = new ArrayList<>(); 291 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 80f, 64f, 40f)); 292 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 122f, 98f, 70f)); 293 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 86f, 58f, 30f)); 294 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 108f, 88f, 67f)); 295 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 92f, 78f, 50f)); 296 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 112f, 98f, 80f)); 297 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 132f, 112f, 99f)); 298 | return datas3; 299 | } 300 | 301 | private List getYearData() { 302 | //年数据源 303 | List datas4 = new ArrayList<>(); 304 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 80f, 64f, 40f)); 305 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 122f, 98f, 70f)); 306 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 86f, 58f, 30f)); 307 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 108f, 88f, 67f)); 308 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 112f, 98f, 80f)); 309 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 132f, 112f, 99f)); 310 | return datas4; 311 | } 312 | } 313 | ``` 314 | ``` 315 | 316 | 321 | 322 | 325 | 326 | 330 | 331 | 335 | 336 | 344 | 345 | 349 | 350 | 358 | 359 | 363 | 364 | 372 | 373 | 377 | 378 | 386 | 387 | 388 | 389 | 390 | 391 | ``` 392 | 393 | #####柱状图: 394 | ``` 395 | public class BarChartFragment extends Fragment { 396 | private BarChartView chartView1; 397 | private BarChartView chartView2; 398 | private BarChartView chartView3; 399 | private BarChartView chartView4; 400 | 401 | @Nullable 402 | @Override 403 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 404 | View view = inflater.inflate(R.layout.fragment_sport_chart, null, false); 405 | chartView1 = (BarChartView) view.findViewById(R.id.weightChart1); 406 | chartView2 = (BarChartView) view.findViewById(R.id.weightChart2); 407 | chartView3 = (BarChartView) view.findViewById(R.id.weightChart3); 408 | chartView4 = (BarChartView) view.findViewById(R.id.weightChart4); 409 | return view; 410 | } 411 | 412 | public void showChart() { 413 | new Handler().postDelayed(new Runnable() { 414 | @Override 415 | public void run() { 416 | chartView1 417 | .setPillarWidth(30f) 418 | .setPillarColor(0x90ff0000)//以上子类内容,必须写在下面方法上面 419 | .isShowDatumLine_X(false) 420 | .isShowDatumLine_Y(false) 421 | .setType(BaseChartView.DAY) 422 | .setYMaxValue(30) 423 | .setUnitValueText("Km") 424 | .refreshData(getDayData()); 425 | chartView2 426 | .isShowDatumLine_X(false) 427 | .isShowDatumLine_Y(false) 428 | .setType(BaseChartView.WEEK) 429 | .setYMaxValue(30) 430 | .setUnitValueText("Km") 431 | .refreshData(getWeekData()); 432 | chartView3 433 | .isShowDatumLine_X(false) 434 | .isShowDatumLine_Y(false) 435 | .setType(BaseChartView.MONTH) 436 | .setYMaxValue(30) 437 | .setUnitValueText("Km") 438 | .refreshData(getMonthData()); 439 | chartView4 440 | .isShowDatumLine_X(false) 441 | .isShowDatumLine_Y(false) 442 | .setType(BaseChartView.YEAR) 443 | .setYMaxValue(30) 444 | .setUnitValueText("Km") 445 | .refreshData(getYearData()); 446 | } 447 | }, 800); 448 | } 449 | 450 | private List getDayData() { 451 | //日数据源 452 | List datas1 = new ArrayList<>(); 453 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 5f)); 454 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 12f)); 455 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 6f)); 456 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 18f)); 457 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 12f)); 458 | return datas1; 459 | } 460 | 461 | private List getWeekData() { 462 | //周数据源 463 | List datas2 = new ArrayList<>(); 464 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 6f)); 465 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 16f)); 466 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 3f)); 467 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 18f)); 468 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 12f)); 469 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 22f)); 470 | return datas2; 471 | } 472 | 473 | private List getMonthData() { 474 | //月数据源 475 | List datas3 = new ArrayList<>(); 476 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 6f)); 477 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 16f)); 478 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 8f)); 479 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 2f)); 480 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 12f)); 481 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 22f)); 482 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 13f)); 483 | return datas3; 484 | } 485 | 486 | private List getYearData() { 487 | //年数据源 488 | List datas4 = new ArrayList<>(); 489 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 6f)); 490 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 16f)); 491 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 8f)); 492 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 2f)); 493 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 12f)); 494 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 22f)); 495 | return datas4; 496 | } 497 | } 498 | ``` 499 | ``` 500 | 501 | 506 | 507 | 510 | 511 | 515 | 516 | 520 | 521 | 529 | 530 | 534 | 535 | 543 | 544 | 548 | 549 | 557 | 558 | 562 | 563 | 571 | 572 | 573 | 574 | 575 | 576 | ``` 577 | 578 | #####镂空柱状图: 579 | ``` 580 | public class HistogramBarChartFragment extends Fragment { 581 | private HistogramBarChartView chartView1; 582 | private HistogramBarChartView chartView2; 583 | private HistogramBarChartView chartView3; 584 | private HistogramBarChartView chartView4; 585 | 586 | @Nullable 587 | @Override 588 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 589 | View view = inflater.inflate(R.layout.fragment_blood_chart, null, false); 590 | chartView1 = (HistogramBarChartView) view.findViewById(R.id.weightChart1); 591 | chartView2 = (HistogramBarChartView) view.findViewById(R.id.weightChart2); 592 | chartView3 = (HistogramBarChartView) view.findViewById(R.id.weightChart3); 593 | chartView4 = (HistogramBarChartView) view.findViewById(R.id.weightChart4); 594 | return view; 595 | } 596 | 597 | public void showChart() { 598 | new Handler().postDelayed(new Runnable() { 599 | @Override 600 | public void run() { 601 | chartView1 602 | .setNoMedicineColor(0xffff0000) 603 | .setMedicineColor(0xff00ff00) 604 | .setNoMedicineText("未打针") 605 | .setMedicineText("打针") 606 | .setBloodText("高针114-128/低针68-78") 607 | .setPillarWidth(26f)//以上子类内容,必须写在下面方法上面 608 | .isShowDatumLine_X(false) 609 | .isShowDatumLine_Y(false) 610 | .setType(BaseChartView.DAY) 611 | .setYMaxValue(240) 612 | .setUnitValueText("mmHg") 613 | .refreshData(getDayData()); 614 | 615 | chartView2 616 | .isShowDatumLine_X(false) 617 | .isShowDatumLine_Y(false) 618 | .setType(BaseChartView.WEEK) 619 | .setYMaxValue(240) 620 | .setUnitValueText("mmHg") 621 | .refreshData(getWeekData()); 622 | chartView3 623 | .isShowDatumLine_X(false) 624 | .isShowDatumLine_Y(false) 625 | .setType(BaseChartView.MONTH) 626 | .setYMaxValue(240) 627 | .setUnitValueText("mmHg") 628 | .refreshData(getMonthData()); 629 | chartView4 630 | .isShowDatumLine_X(false) 631 | .isShowDatumLine_Y(false) 632 | .setType(BaseChartView.YEAR) 633 | .setYMaxValue(240) 634 | .setUnitValueText("mmHg") 635 | .refreshData(getYearData()); 636 | } 637 | }, 800); 638 | } 639 | 640 | private List getDayData() { 641 | //日数据源 642 | List datas1 = new ArrayList<>(); 643 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 60f, 30f, false)); 644 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 122f, 60f, false)); 645 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 86f, 40f, true)); 646 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 108f, 80f, false)); 647 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 92f, 10f, true)); 648 | return datas1; 649 | } 650 | 651 | private List getWeekData() { 652 | //周数据源 653 | List datas2 = new ArrayList<>(); 654 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 60f, 40f, true)); 655 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 86f, 70f, false)); 656 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 86f, 20f, true)); 657 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 68f, 30f, false)); 658 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 72f, 33f, true)); 659 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 112f, 60f, true)); 660 | datas2.add(new BaseChartView.DataBean("2017-08-27 16:17:00", 122f, 80f, true)); 661 | return datas2; 662 | } 663 | 664 | private List getMonthData() { 665 | //月数据源 666 | List datas3 = new ArrayList<>(); 667 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 60f, 40f, false)); 668 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 116f, 92f, true)); 669 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 98f, 70f, true)); 670 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 52f, 30f, false)); 671 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 102f, 20f, true)); 672 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 82f, 60f, true)); 673 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 132f, 110f, true)); 674 | return datas3; 675 | } 676 | 677 | private List getYearData() { 678 | //年数据源 679 | List datas4 = new ArrayList<>(); 680 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 60f, 30f, true)); 681 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 116f, 100f, false)); 682 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 86f, 33f, false)); 683 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 72f, 20f, true)); 684 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 122f, 85f, false)); 685 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 82f, 60f, true)); 686 | return datas4; 687 | } 688 | } 689 | ``` 690 | ``` 691 | 692 | 697 | 698 | 701 | 702 | 706 | 707 | 711 | 712 | 720 | 721 | 725 | 726 | 734 | 735 | 739 | 740 | 748 | 749 | 753 | 754 | 762 | 763 | 764 | 765 | 766 | 767 | ``` 768 | #####定制血压图: 769 | ``` 770 | public class CustomizedBloodChartFragment extends Fragment { 771 | private CustomizedBloodChartView chartView1; 772 | private CustomizedBloodChartView chartView2; 773 | private CustomizedBloodChartView chartView3; 774 | private CustomizedBloodChartView chartView4; 775 | 776 | @Nullable 777 | @Override 778 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 779 | View view = inflater.inflate(R.layout.fragment_blood_chart_, null, false); 780 | chartView1 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart1); 781 | chartView2 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart2); 782 | chartView3 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart3); 783 | chartView4 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart4); 784 | return view; 785 | } 786 | 787 | public void showChart() { 788 | new Handler().postDelayed(new Runnable() { 789 | @Override 790 | public void run() { 791 | chartView1 792 | .setNoMedicineColor(0xffff0000) 793 | .setMedicineColor(0xff00ff00) 794 | .setNoMedicineText("未打针") 795 | .setMedicineText("打针") 796 | .setBloodText("高针114-128/低针68-78") 797 | .setMedicineScaleColor(0x900000ff) 798 | .setNoMedicineScaleColor(0x9000ffff) 799 | .setPillarWidth(26f)//以上子类内容,必须写在下面方法上面 800 | .isShowDatumLine_X(false) 801 | .isShowDatumLine_Y(false) 802 | .setType(BaseChartView.DAY) 803 | .setYMaxValue(240) 804 | .setUnitValueText("mmHg") 805 | .refreshData(getDayData()); 806 | chartView2 807 | .isShowDatumLine_X(false) 808 | .isShowDatumLine_Y(false) 809 | .setType(BaseChartView.WEEK) 810 | .setYMaxValue(240) 811 | .setUnitValueText("mmHg") 812 | .refreshData(getWeekData()); 813 | chartView3 814 | .isShowDatumLine_X(false) 815 | .isShowDatumLine_Y(false) 816 | .setType(BaseChartView.MONTH) 817 | .setYMaxValue(240) 818 | .setUnitValueText("mmHg") 819 | .refreshData(getMonthData()); 820 | chartView4 821 | .isShowDatumLine_X(false) 822 | .isShowDatumLine_Y(false) 823 | .setType(BaseChartView.YEAR) 824 | .setYMaxValue(240) 825 | .setUnitValueText("mmHg") 826 | .refreshData(getYearData()); 827 | } 828 | }, 800); 829 | } 830 | 831 | private List getDayData() { 832 | //日数据源 833 | List datas1 = new ArrayList<>();//高压最高、高压最低,低压最高、低压最低 834 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 835 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", new float[]{108f, 87f}, new float[]{73f, 57f}, false)); 836 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", new float[]{88f, 67f}, new float[]{60f, 57f}, true)); 837 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", new float[]{120f, 117f}, new float[]{90f, 87f}, false)); 838 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", new float[]{110f, 97f}, new float[]{80f, 67f}, true)); 839 | return datas1; 840 | } 841 | 842 | private List getWeekData() { 843 | //周数据源 844 | List datas2 = new ArrayList<>(); 845 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 846 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 847 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 848 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 849 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 850 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 851 | return datas2; 852 | } 853 | 854 | private List getMonthData() { 855 | //月数据源 856 | List datas3 = new ArrayList<>(); 857 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 858 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 859 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 860 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 861 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 862 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 863 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 864 | return datas3; 865 | } 866 | 867 | private List getYearData() { 868 | //年数据源 869 | List datas4 = new ArrayList<>(); 870 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", new float[]{100f, 87f}, new float[]{80f, 67f}, true)); 871 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", new float[]{110f, 67f}, new float[]{50f, 37f}, false)); 872 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", new float[]{90f, 77f}, new float[]{60f, 47f}, false)); 873 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 874 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 875 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 876 | return datas4; 877 | } 878 | } 879 | ``` 880 | ``` 881 | 882 | 887 | 888 | 891 | 892 | 896 | 897 | 901 | 902 | 910 | 911 | 915 | 916 | 924 | 925 | 929 | 930 | 938 | 939 | 943 | 944 | 952 | 953 | 954 | 955 | 956 | 957 | ``` 958 | 959 | #####以上就是这次图表的所有内容,如果在使用过程中遇到问题或更好的建议,欢迎留言私信,作者将竭诚解决。最后,有帮助到您的欢迎点赞关注,您的支持是对作者最大的支持,谢谢! -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "com.example.chartview" 8 | minSdkVersion 15 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 | repositories { 22 | flatDir { 23 | dirs 'libs' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(include: ['*.jar'], dir: 'libs') 30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 31 | exclude group: 'com.android.support', module: 'support-annotations' 32 | }) 33 | compile 'com.android.support:appcompat-v7:25.3.1' 34 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 35 | testCompile 'junit:junit:4.12' 36 | compile 'com.android.support:design:26.0.0-alpha1' 37 | compile project(':chart') 38 | //compile 'me.hwc:chart:1.0.2' 39 | 40 | compile(name: 'httplib-release', ext: 'aar') 41 | } 42 | -------------------------------------------------------------------------------- /app/libs/httplib-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangweicai/ChartView/aa6aa5ba9bf9483d79b7619c6a2f9e7953e25859/app/libs/httplib-release.aar -------------------------------------------------------------------------------- /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 C:\Users\huangweicai\AppData\Local\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/chartview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview; 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.example.chartview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/FllowerViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.Toast; 9 | 10 | import com.example.chartview.view.FllowerAnimation; 11 | 12 | /** 13 | * 时间:2017/8/18 14 | * 作者:黄伟才 15 | * 简书:http://www.jianshu.com/p/87e7392a16ff 16 | * github:https://github.com/huangweicai/OkLibDemo 17 | * 描述: 18 | */ 19 | 20 | public class FllowerViewActivity extends AppCompatActivity { 21 | @Override 22 | protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_fllower_view); 25 | final FllowerAnimation fllower = (FllowerAnimation) findViewById(R.id.fllower); 26 | 27 | Button btn_start = (Button) findViewById(R.id.btn_start); 28 | btn_start.setOnClickListener(new View.OnClickListener() { 29 | @Override 30 | public void onClick(View v) { 31 | Toast.makeText(v.getContext(), "撒花", Toast.LENGTH_LONG).show(); 32 | fllower.startAnimation(); 33 | } 34 | }); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.TabLayout; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.app.FragmentStatePagerAdapter; 7 | import android.support.v4.view.ViewPager; 8 | import android.support.v7.app.AppCompatActivity; 9 | 10 | import com.example.chartview.fragment.BarChartFragment; 11 | import com.example.chartview.fragment.CurveChartFragment; 12 | import com.example.chartview.fragment.CustomizedBloodChartFragment; 13 | import com.example.chartview.fragment.HistogramBarChartFragment; 14 | import com.example.chartview.fragment.LineChartFragment; 15 | import com.example.chartview.fragment.SportBarChartFragment; 16 | import com.example.chartview.fragment.StackBarChartFragment; 17 | import com.hwc.oklib.http.okhttp.OkGo; 18 | import com.hwc.oklib.http.okhttp.callback.StringCallback; 19 | 20 | /** 21 | * 时间:2017/8/23 22 | * 作者:黄伟才 23 | * 简书:http://www.jianshu.com/p/87e7392a16ff 24 | * github:https://github.com/huangweicai/OkLibDemo 25 | * 描述:合并分支 26 | */ 27 | public class MainActivity extends AppCompatActivity { 28 | private TabLayout toolbar_tl_tab; 29 | private ViewPager vp_container; 30 | private String[] titles = {"折线图", "曲线图", "柱状图", "镂空柱状图", "定制血压图", "运动柱状图", "堆叠柱状图"}; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | toolbar_tl_tab = (TabLayout) findViewById(R.id.toolbar_tl_tab); 37 | vp_container = (ViewPager) findViewById(R.id.vp_container); 38 | toolbar_tl_tab.setupWithViewPager(vp_container); 39 | toolbar_tl_tab.setTabMode(TabLayout.MODE_SCROLLABLE); 40 | vp_container.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) { 41 | @Override 42 | public Fragment getItem(int position) { 43 | if (position == 0) { 44 | //折线图 45 | LineChartFragment chartFragment = new LineChartFragment(); 46 | chartFragment.showChart(); 47 | return chartFragment; 48 | } else if (position == 1) { 49 | //曲线图 50 | CurveChartFragment chartFragment = new CurveChartFragment(); 51 | chartFragment.showChart(); 52 | return chartFragment; 53 | } else if (position == 2) { 54 | //柱状图 55 | BarChartFragment chartFragment = new BarChartFragment(); 56 | chartFragment.showChart(); 57 | return chartFragment; 58 | } else if (position == 3) { 59 | //镂空柱状图 60 | HistogramBarChartFragment chartFragment = new HistogramBarChartFragment(); 61 | chartFragment.showChart(); 62 | return chartFragment; 63 | } else if (position == 4) { 64 | //定制血压图 65 | CustomizedBloodChartFragment chartFragment = new CustomizedBloodChartFragment(); 66 | chartFragment.showChart(); 67 | return chartFragment; 68 | } else if (position == 5) { 69 | //运动柱状图 70 | SportBarChartFragment chartFragment = new SportBarChartFragment(); 71 | chartFragment.showChart(); 72 | return chartFragment; 73 | }else if (position == 6) { 74 | //堆叠柱状图 75 | StackBarChartFragment chartFragment = new StackBarChartFragment(); 76 | chartFragment.showChart(); 77 | return chartFragment; 78 | } 79 | return null; 80 | } 81 | 82 | @Override 83 | public CharSequence getPageTitle(int position) { 84 | return titles[position]; 85 | } 86 | 87 | @Override 88 | public int getCount() { 89 | return titles.length; 90 | } 91 | }); 92 | } 93 | 94 | 95 | private void testOkGo() { 96 | 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/bean/Fllower.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.bean; 2 | 3 | import android.graphics.Path; 4 | 5 | /** 6 | * 时间:2017/8/18 7 | * 作者:黄伟才 8 | * 简书:http://www.jianshu.com/p/87e7392a16ff 9 | * github:https://github.com/huangweicai/OkLibDemo 10 | * 描述: 11 | */ 12 | 13 | public class Fllower { 14 | 15 | private Path path; 16 | private float Value; 17 | 18 | public Path getPath() { 19 | return path; 20 | } 21 | 22 | public void setPath(Path path) { 23 | this.path = path; 24 | } 25 | 26 | public float getValue() { 27 | return Value; 28 | } 29 | 30 | public void setValue(float value) { 31 | Value = value; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/BarChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.example.chartview.R; 12 | import com.hwc.chart.BarChartView; 13 | import com.hwc.chart.BaseChartView; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * 时间:2017/8/16 20 | * 作者:黄伟才 21 | * 简书:http://www.jianshu.com/p/87e7392a16ff 22 | * github:https://github.com/huangweicai/OkLibDemo 23 | * 描述: 24 | */ 25 | 26 | public class BarChartFragment extends Fragment { 27 | private BarChartView chartView1; 28 | private BarChartView chartView2; 29 | private BarChartView chartView3; 30 | private BarChartView chartView4; 31 | 32 | @Nullable 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | View view = inflater.inflate(R.layout.fragment_barchart, null, false); 36 | chartView1 = (BarChartView) view.findViewById(R.id.weightChart1); 37 | chartView2 = (BarChartView) view.findViewById(R.id.weightChart2); 38 | chartView3 = (BarChartView) view.findViewById(R.id.weightChart3); 39 | chartView4 = (BarChartView) view.findViewById(R.id.weightChart4); 40 | return view; 41 | } 42 | 43 | public void showChart() { 44 | new Handler().postDelayed(new Runnable() { 45 | @Override 46 | public void run() { 47 | chartView1 48 | .setPillarWidth(30f) 49 | .setPillarColor(0x90ff0000)//以上子类内容,必须写在下面方法上面 50 | .isShowDatumLine_X(false) 51 | .isShowDatumLine_Y(false) 52 | .setType(BaseChartView.DAY) 53 | .setYMaxValue(30) 54 | .setUnitValueText("Km") 55 | .refreshData(getDayData()); 56 | chartView2 57 | .isShowDatumLine_X(false) 58 | .isShowDatumLine_Y(false) 59 | .setType(BaseChartView.WEEK) 60 | .setYMaxValue(30) 61 | .setUnitValueText("Km") 62 | .refreshData(getWeekData()); 63 | chartView3 64 | .isShowDatumLine_X(false) 65 | .isShowDatumLine_Y(false) 66 | .setType(BaseChartView.MONTH) 67 | .setYMaxValue(30) 68 | .setUnitValueText("Km") 69 | .refreshData(getMonthData()); 70 | chartView4 71 | .isShowDatumLine_X(false) 72 | .isShowDatumLine_Y(false) 73 | .setType(BaseChartView.YEAR) 74 | .setYMaxValue(30) 75 | .setUnitValueText("Km") 76 | .refreshData(getYearData()); 77 | } 78 | }, 800); 79 | } 80 | 81 | private List getDayData() { 82 | //日数据源 83 | List datas1 = new ArrayList<>(); 84 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 5f)); 85 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 12f)); 86 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 6f)); 87 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 18f)); 88 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 12f)); 89 | return datas1; 90 | } 91 | 92 | private List getWeekData() { 93 | //周数据源 94 | List datas2 = new ArrayList<>(); 95 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 6f)); 96 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 16f)); 97 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 3f)); 98 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 18f)); 99 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 12f)); 100 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 22f)); 101 | return datas2; 102 | } 103 | 104 | private List getMonthData() { 105 | //月数据源 106 | List datas3 = new ArrayList<>(); 107 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 6f)); 108 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 16f)); 109 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 8f)); 110 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 2f)); 111 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 12f)); 112 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 22f)); 113 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 13f)); 114 | return datas3; 115 | } 116 | 117 | private List getYearData() { 118 | //年数据源 119 | List datas4 = new ArrayList<>(); 120 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 6f)); 121 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 16f)); 122 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 8f)); 123 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 2f)); 124 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 12f)); 125 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 22f)); 126 | return datas4; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/CurveChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.graphics.Canvas; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.example.chartview.R; 13 | import com.hwc.chart.BaseChartView; 14 | import com.hwc.chart.CurveChartView; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | 20 | 21 | /** 22 | * 时间:2017/8/16 23 | * 作者:黄伟才 24 | * 简书:http://www.jianshu.com/p/87e7392a16ff 25 | * github:https://github.com/huangweicai/OkLibDemo 26 | * 描述: 27 | */ 28 | 29 | public class CurveChartFragment extends Fragment { 30 | private CurveChartView chartView1; 31 | private CurveChartView chartView2; 32 | private CurveChartView chartView3; 33 | private CurveChartView chartView4; 34 | 35 | @Nullable 36 | @Override 37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 38 | View view = inflater.inflate(R.layout.fragment_curvechart, null, false); 39 | chartView1 = (CurveChartView) view.findViewById(R.id.weightChart1); 40 | chartView2 = (CurveChartView) view.findViewById(R.id.weightChart2); 41 | chartView3 = (CurveChartView) view.findViewById(R.id.weightChart3); 42 | chartView4 = (CurveChartView) view.findViewById(R.id.weightChart4); 43 | 44 | List list = getDayData(); 45 | chartView1 46 | .seMaxLineColor(0xffff0000) 47 | .setMaxTextColor(0xffff0000) 48 | .setAvgLineColor(0xff00ff00) 49 | .setAvgTextColor(0xff00ff00) 50 | .setMinLineColor(0xff0000ff) 51 | .setMinTextColor(0xff0000ff) 52 | .setLineWidht(10)//以上子类内容,必须写在下面方法上面 53 | .isShowDatumLine_X(false) 54 | .isShowDatumLine_Y(false) 55 | .setType(BaseChartView.DAY) 56 | .setYMaxValue(220) 57 | .setUnitValueText("bpm") 58 | .refreshData(list); 59 | chartView1.setOnDrawListener(new CurveChartView.OnDrawListener() { 60 | @Override 61 | public void onDraw(Canvas canvas) { 62 | chartView1.drawData(canvas); 63 | } 64 | }); 65 | return view; 66 | } 67 | 68 | public void showChart() { 69 | 70 | new Handler().postDelayed(new Runnable() { 71 | @Override 72 | public void run() { 73 | 74 | chartView2 75 | .seMaxLineColor(0x00ff0000) 76 | .setMaxTextColor(0x00ff0000) 77 | .setAvgLineColor(0x0000ff00) 78 | .setAvgTextColor(0x0000ff00) 79 | .setMinLineColor(0xff0000ff) 80 | .setMinTextColor(0xff0000ff) 81 | .setLineWidht(10)//以上子类内容,必须写在下面方法上面 82 | .isShowDatumLine_X(false) 83 | .isShowDatumLine_Y(false) 84 | .setType(BaseChartView.WEEK) 85 | .setYMaxValue(220) 86 | .setUnitValueText("bpm") 87 | .setChartColor(0x00000000) 88 | .refreshData(getWeekData()); 89 | chartView3 90 | .isShowDatumLine_X(false) 91 | .isShowDatumLine_Y(false) 92 | .setType(BaseChartView.MONTH) 93 | .setYMaxValue(220) 94 | .setUnitValueText("bpm") 95 | .refreshData(getMonthData()); 96 | chartView4 97 | .isShowDatumLine_X(false) 98 | .isShowDatumLine_Y(false) 99 | .setType(BaseChartView.YEAR) 100 | .setYMaxValue(220) 101 | .setUnitValueText("bpm") 102 | .refreshData(getYearData()); 103 | } 104 | }, 800); 105 | } 106 | 107 | private List getDayData() { 108 | //日数据源 109 | List datas1 = new ArrayList<>(); 110 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 80f, 64f, 40f)); 111 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 122f, 98f, 70f)); 112 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 86f, 58f, 30f)); 113 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 108f, 88f, 67f)); 114 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 92f, 78f, 50f)); 115 | return datas1; 116 | } 117 | 118 | private List getWeekData() { 119 | //周数据源 120 | List datas2 = new ArrayList<>(); 121 | // datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 80f, 64f, 40f)); 122 | // datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 122f, 98f, 70f)); 123 | // datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 86f, 58f, 30f)); 124 | // datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 108f, 88f, 67f)); 125 | // datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 92f, 78f, 50f)); 126 | // datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 112f, 98f, 80f)); 127 | datas2.add(new BaseChartView.DataBean("2017-09-04 16:17:00", 80f, 0, 0)); 128 | datas2.add(new BaseChartView.DataBean("2017-09-05 16:17:00", 90f, 0, 0)); 129 | datas2.add(new BaseChartView.DataBean("2017-09-06 16:17:00", 100f, 0, 0)); 130 | datas2.add(new BaseChartView.DataBean("2017-09-07 16:17:00", 111f, 0, 0)); 131 | datas2.add(new BaseChartView.DataBean("2017-09-08 16:17:00", 120f, 0, 0)); 132 | datas2.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 130f, 0, 0)); 133 | return datas2; 134 | } 135 | 136 | private List getMonthData() { 137 | //月数据源 138 | List datas3 = new ArrayList<>(); 139 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 80f, 64f, 40f)); 140 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 122f, 98f, 70f)); 141 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 86f, 58f, 30f)); 142 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 108f, 88f, 67f)); 143 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 92f, 78f, 50f)); 144 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 112f, 98f, 80f)); 145 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 132f, 112f, 99f)); 146 | return datas3; 147 | } 148 | 149 | private List getYearData() { 150 | //年数据源 151 | List datas4 = new ArrayList<>(); 152 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 80f, 64f, 40f)); 153 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 122f, 98f, 70f)); 154 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 86f, 58f, 30f)); 155 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 108f, 88f, 67f)); 156 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 112f, 98f, 80f)); 157 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 132f, 112f, 99f)); 158 | return datas4; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/CustomizedBloodChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.example.chartview.R; 12 | import com.hwc.chart.BaseChartView; 13 | import com.hwc.chart.CustomizedBloodChartView; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * 时间:2017/8/16 20 | * 作者:黄伟才 21 | * 简书:http://www.jianshu.com/p/87e7392a16ff 22 | * github:https://github.com/huangweicai/OkLibDemo 23 | * 描述: 24 | */ 25 | 26 | public class CustomizedBloodChartFragment extends Fragment { 27 | private CustomizedBloodChartView chartView1; 28 | private CustomizedBloodChartView chartView2; 29 | private CustomizedBloodChartView chartView3; 30 | private CustomizedBloodChartView chartView4; 31 | 32 | @Nullable 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | View view = inflater.inflate(R.layout.fragment_cbarchart, null, false); 36 | chartView1 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart1); 37 | chartView2 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart2); 38 | chartView3 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart3); 39 | chartView4 = (CustomizedBloodChartView) view.findViewById(R.id.weightChart4); 40 | return view; 41 | } 42 | 43 | public void showChart() { 44 | new Handler().postDelayed(new Runnable() { 45 | @Override 46 | public void run() { 47 | chartView1 48 | .setNoMedicineColor(0xffff0000) 49 | .setMedicineColor(0xff00ff00) 50 | .setNoMedicineText("未打针") 51 | .setMedicineText("打针") 52 | .setBloodText("高针114-128/低针68-78") 53 | .setMedicineScaleColor(0x900000ff) 54 | .setNoMedicineScaleColor(0x9000ffff) 55 | .setPillarWidth(26f)//以上子类内容,必须写在下面方法上面 56 | .isShowDatumLine_X(false) 57 | .isShowDatumLine_Y(false) 58 | .setType(BaseChartView.DAY) 59 | .setYMaxValue(240) 60 | .setUnitValueText("mmHg") 61 | .refreshData(getDayData()); 62 | chartView2 63 | .isShowDatumLine_X(false) 64 | .isShowDatumLine_Y(false) 65 | .setType(BaseChartView.WEEK) 66 | .setYMaxValue(240) 67 | .setUnitValueText("mmHg") 68 | .refreshData(getWeekData()); 69 | chartView3 70 | .isShowDatumLine_X(false) 71 | .isShowDatumLine_Y(false) 72 | .setType(BaseChartView.MONTH) 73 | .setYMaxValue(240) 74 | .setUnitValueText("mmHg") 75 | .refreshData(getMonthData()); 76 | chartView4 77 | .isShowDatumLine_X(false) 78 | .isShowDatumLine_Y(false) 79 | .setType(BaseChartView.YEAR) 80 | .setYMaxValue(240) 81 | .setUnitValueText("mmHg") 82 | .refreshData(getYearData()); 83 | } 84 | }, 800); 85 | } 86 | 87 | private List getDayData() { 88 | //日数据源 89 | List datas1 = new ArrayList<>();//高压最高、高压最低,低压最高、低压最低 90 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 91 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", new float[]{108f, 87f}, new float[]{73f, 57f}, false)); 92 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", new float[]{88f, 67f}, new float[]{60f, 57f}, true)); 93 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", new float[]{120f, 117f}, new float[]{90f, 87f}, false)); 94 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", new float[]{110f, 97f}, new float[]{80f, 67f}, true)); 95 | return datas1; 96 | } 97 | 98 | private List getWeekData() { 99 | //周数据源 100 | List datas2 = new ArrayList<>(); 101 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 102 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 103 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 104 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 105 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 106 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 107 | return datas2; 108 | } 109 | 110 | private List getMonthData() { 111 | //月数据源 112 | List datas3 = new ArrayList<>(); 113 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 114 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 115 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 116 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 117 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 118 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 119 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 120 | return datas3; 121 | } 122 | 123 | private List getYearData() { 124 | //年数据源 125 | List datas4 = new ArrayList<>(); 126 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", new float[]{100f, 87f}, new float[]{80f, 67f}, true)); 127 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", new float[]{110f, 67f}, new float[]{50f, 37f}, false)); 128 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", new float[]{90f, 77f}, new float[]{60f, 47f}, false)); 129 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 130 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, false)); 131 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", new float[]{80f, 67f}, new float[]{50f, 37f}, true)); 132 | return datas4; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/HistogramBarChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.example.chartview.R; 12 | import com.hwc.chart.BaseChartView; 13 | import com.hwc.chart.HistogramBarChartView; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * 时间:2017/8/16 20 | * 作者:黄伟才 21 | * 简书:http://www.jianshu.com/p/87e7392a16ff 22 | * github:https://github.com/huangweicai/OkLibDemo 23 | * 描述: 24 | */ 25 | 26 | public class HistogramBarChartFragment extends Fragment { 27 | private HistogramBarChartView chartView1; 28 | private HistogramBarChartView chartView2; 29 | private HistogramBarChartView chartView3; 30 | private HistogramBarChartView chartView4; 31 | 32 | @Nullable 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | View view = inflater.inflate(R.layout.fragment_hbarchart, null, false); 36 | chartView1 = (HistogramBarChartView) view.findViewById(R.id.weightChart1); 37 | chartView2 = (HistogramBarChartView) view.findViewById(R.id.weightChart2); 38 | chartView3 = (HistogramBarChartView) view.findViewById(R.id.weightChart3); 39 | chartView4 = (HistogramBarChartView) view.findViewById(R.id.weightChart4); 40 | return view; 41 | } 42 | 43 | public void showChart() { 44 | new Handler().postDelayed(new Runnable() { 45 | @Override 46 | public void run() { 47 | chartView1 48 | .setPillarLightColor(0xffff0000) 49 | .setPillarColor(0xff00ff00) 50 | .setPillarLeftLightText("未打针") 51 | .setPillarLeftText("打针") 52 | .setPillarRightText("高针114-128/低针68-78") 53 | .setPillarWidth(26f) 54 | .setShowYCenterText(true) 55 | .setShowTopInfo(true)//以上子类内容,必须写在下面方法上面 56 | .isShowDatumLine_X(false) 57 | .isShowDatumLine_Y(false) 58 | .setType(BaseChartView.DAY) 59 | .setYMaxValue(240) 60 | .setUnitValueText("mmHg") 61 | .setChartColor(0xFFF89A3C) 62 | .refreshData(getDayData()); 63 | 64 | chartView2 65 | .isShowDatumLine_X(false) 66 | .isShowDatumLine_Y(false) 67 | .setType(BaseChartView.WEEK) 68 | .setYMaxValue(240) 69 | .setUnitValueText("mmHg") 70 | .refreshData(getWeekData()); 71 | chartView3 72 | .isShowDatumLine_X(false) 73 | .isShowDatumLine_Y(false) 74 | .setType(BaseChartView.MONTH) 75 | .setYMaxValue(240) 76 | .setUnitValueText("mmHg") 77 | .refreshData(getMonthData()); 78 | chartView4 79 | .isShowDatumLine_X(false) 80 | .isShowDatumLine_Y(false) 81 | .setType(BaseChartView.YEAR) 82 | .setYMaxValue(240) 83 | .setUnitValueText("mmHg") 84 | .refreshData(getYearData()); 85 | } 86 | }, 800); 87 | } 88 | 89 | private List getDayData() { 90 | //日数据源 91 | List datas1 = new ArrayList<>(); 92 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 60f, 30f, false)); 93 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 122f, 60f, false)); 94 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 86f, 40f, true)); 95 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 108f, 80f, false)); 96 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 92f, 10f, true)); 97 | return datas1; 98 | } 99 | 100 | private List getWeekData() { 101 | //周数据源 102 | List datas2 = new ArrayList<>(); 103 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 60f, 40f, true)); 104 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 86f, 70f, false)); 105 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 86f, 20f, true)); 106 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 68f, 30f, false)); 107 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 72f, 33f, true)); 108 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 112f, 60f, true)); 109 | datas2.add(new BaseChartView.DataBean("2017-08-27 16:17:00", 122f, 80f, true)); 110 | return datas2; 111 | } 112 | 113 | private List getMonthData() { 114 | //月数据源 115 | List datas3 = new ArrayList<>(); 116 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 60f, 40f, false)); 117 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 116f, 92f, true)); 118 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 98f, 70f, true)); 119 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 52f, 30f, false)); 120 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 102f, 20f, true)); 121 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 82f, 60f, true)); 122 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 132f, 110f, true)); 123 | return datas3; 124 | } 125 | 126 | private List getYearData() { 127 | //年数据源 128 | List datas4 = new ArrayList<>(); 129 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 60f, 30f, true)); 130 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 116f, 100f, false)); 131 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 86f, 33f, false)); 132 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 72f, 20f, true)); 133 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 122f, 85f, false)); 134 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 82f, 60f, true)); 135 | return datas4; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/LineChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.example.chartview.R; 12 | import com.hwc.chart.BaseChartView; 13 | import com.hwc.chart.LineChartView; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * 时间:2017/8/16 21 | * 作者:黄伟才 22 | * 简书:http://www.jianshu.com/p/87e7392a16ff 23 | * github:https://github.com/huangweicai/OkLibDemo 24 | * 描述: 25 | */ 26 | 27 | public class LineChartFragment extends Fragment { 28 | private LineChartView chartView1; 29 | private LineChartView chartView2; 30 | private LineChartView chartView3; 31 | private LineChartView chartView4; 32 | 33 | @Nullable 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 36 | View view = inflater.inflate(R.layout.fragment_linechart, null, false); 37 | chartView1 = (LineChartView) view.findViewById(R.id.weightChart1); 38 | chartView2 = (LineChartView) view.findViewById(R.id.weightChart2); 39 | chartView3 = (LineChartView) view.findViewById(R.id.weightChart3); 40 | chartView4 = (LineChartView) view.findViewById(R.id.weightChart4); 41 | return view; 42 | } 43 | 44 | public void showChart() { 45 | //注意:图表使用一定要延迟使用 46 | new Handler().postDelayed(new Runnable() { 47 | @Override 48 | public void run() { 49 | chartView1 50 | .setLineColor(0xffff0000) 51 | .setTextColor(0xff0000ff) 52 | .setCircleColor(0xff00ff00) 53 | .setTextSize(24) 54 | .setCircleRadiusSize(14) 55 | .setLineSize(10)//以上子类内容,必须写在下面方法上面 56 | .isShowDatumLine_X(false) 57 | .isShowDatumLine_Y(false) 58 | .setType(BaseChartView.DAY) 59 | .setYMaxValue(150) 60 | .setUnitValueText("Kg") 61 | .refreshData(getDayData()); 62 | chartView2 63 | .isShowDatumLine_X(false) 64 | .isShowDatumLine_Y(false) 65 | .setType(BaseChartView.WEEK) 66 | .setYMaxValue(150) 67 | .setUnitValueText("Kg") 68 | .refreshData(getWeekData()); 69 | chartView3 70 | .isShowDatumLine_X(false) 71 | .isShowDatumLine_Y(false) 72 | .setType(BaseChartView.MONTH) 73 | .setYMaxValue(150) 74 | .setUnitValueText("Kg") 75 | .refreshData(getMonthData()); 76 | chartView4 77 | .isShowDatumLine_X(false) 78 | .isShowDatumLine_Y(false) 79 | .setType(BaseChartView.YEAR) 80 | .setYMaxValue(150) 81 | .setUnitValueText("Kg") 82 | .refreshData(getYearData()); 83 | } 84 | }, 800); 85 | } 86 | 87 | private List getDayData() { 88 | //日数据源 89 | List datas1 = new ArrayList<>(); 90 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 60f)); 91 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 122f)); 92 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 86f)); 93 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 108f)); 94 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 92f)); 95 | datas1.add(new BaseChartView.DataBean("20170804 241700", 92f)); 96 | return datas1; 97 | } 98 | 99 | private List getWeekData() { 100 | //周数据源 101 | List datas2 = new ArrayList<>(); 102 | datas2.add(new BaseChartView.DataBean("2017-08-21 16:17:00", 60f)); 103 | datas2.add(new BaseChartView.DataBean("2017-08-22 16:17:00", 86f)); 104 | datas2.add(new BaseChartView.DataBean("2017-08-23 16:17:00", 86f)); 105 | datas2.add(new BaseChartView.DataBean("2017-08-24 16:17:00", 68f)); 106 | datas2.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 72f)); 107 | datas2.add(new BaseChartView.DataBean("2017-08-26 16:17:00", 112f)); 108 | return datas2; 109 | } 110 | 111 | private List getMonthData() { 112 | //月数据源 113 | List datas3 = new ArrayList<>(); 114 | datas3.add(new BaseChartView.DataBean("2017-08-01 16:17:00", 60f)); 115 | datas3.add(new BaseChartView.DataBean("2017-08-05 16:17:00", 116f)); 116 | datas3.add(new BaseChartView.DataBean("2017-08-10 16:17:00", 98f)); 117 | datas3.add(new BaseChartView.DataBean("2017-08-15 16:17:00", 52f)); 118 | datas3.add(new BaseChartView.DataBean("2017-08-20 16:17:00", 102f)); 119 | datas3.add(new BaseChartView.DataBean("2017-08-25 16:17:00", 82f)); 120 | datas3.add(new BaseChartView.DataBean("2017-08-30 16:17:00", 132f)); 121 | return datas3; 122 | } 123 | 124 | private List getYearData() { 125 | //年数据源 126 | List datas4 = new ArrayList<>(); 127 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 60f)); 128 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 116f)); 129 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 86f)); 130 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 72f)); 131 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 122f)); 132 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 82f)); 133 | return datas4; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/SportBarChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.example.chartview.R; 12 | import com.hwc.chart.BaseChartView; 13 | import com.hwc.chart.SportBarChartView; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * 时间:2017/8/16 20 | * 作者:黄伟才 21 | * 简书:http://www.jianshu.com/p/87e7392a16ff 22 | * github:https://github.com/huangweicai/OkLibDemo 23 | * 描述:运动图表·当日 24 | */ 25 | 26 | public class SportBarChartFragment extends Fragment { 27 | private SportBarChartView sportChart; 28 | 29 | @Nullable 30 | @Override 31 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 32 | View view = inflater.inflate(R.layout.fragment_sportchart, null, false); 33 | sportChart = (SportBarChartView) view.findViewById(R.id.sportChart); 34 | return view; 35 | } 36 | 37 | public void showChart() { 38 | new Handler().postDelayed(new Runnable() { 39 | @Override 40 | public void run() { 41 | sportChart 42 | .setPillarLightColor(0x90ffffff) 43 | .setPillarColor(0xffffffff) 44 | .setPillarWidth(16f)//以上子类内容,必须写在下面方法上面 45 | .isShowDatumLine_X(false) 46 | .isShowDatumLine_Y(false) 47 | .setType(BaseChartView.DAY) 48 | .setYMaxValue(240) 49 | .setUnitValueText("mmHg") 50 | .setChartColor(0xffffffff) 51 | .refreshData(getDayData()); 52 | } 53 | }, 800); 54 | } 55 | 56 | private List getDayData() { 57 | //日数据源,累加,最大值是下一次的最小值 58 | List datas1 = new ArrayList<>(); 59 | datas1.add(new BaseChartView.DataBean("2017-08-04 00:17:00", 40f, 20f, true)); 60 | datas1.add(new BaseChartView.DataBean("2017-08-04 06:17:00", 52f, 40f, true)); 61 | datas1.add(new BaseChartView.DataBean("2017-08-04 12:17:00", 76f, 52f, true)); 62 | datas1.add(new BaseChartView.DataBean("2017-08-04 18:17:00", 98f, 76f, true)); 63 | datas1.add(new BaseChartView.DataBean("2017-08-04 24:17:00", 112f, 98f, false)); 64 | return datas1; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/fragment/StackBarChartFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.example.chartview.R; 12 | import com.hwc.chart.BaseChartView; 13 | import com.hwc.chart.StackBarChartView; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * 时间:2017/8/16 21 | * 作者:黄伟才 22 | * 简书:http://www.jianshu.com/p/87e7392a16ff 23 | * github:https://github.com/huangweicai/OkLibDemo 24 | * 描述:堆叠柱状图 25 | */ 26 | 27 | public class StackBarChartFragment extends Fragment { 28 | private StackBarChartView chartView1; 29 | private StackBarChartView chartView2; 30 | private StackBarChartView chartView3; 31 | private StackBarChartView chartView4; 32 | 33 | @Nullable 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 36 | View view = inflater.inflate(R.layout.fragment_stack_bar_chart, null, false); 37 | chartView1 = (StackBarChartView) view.findViewById(R.id.weightChart1); 38 | chartView2 = (StackBarChartView) view.findViewById(R.id.weightChart2); 39 | chartView3 = (StackBarChartView) view.findViewById(R.id.weightChart3); 40 | chartView4 = (StackBarChartView) view.findViewById(R.id.weightChart4); 41 | return view; 42 | } 43 | 44 | public void showChart() { 45 | new Handler().postDelayed(new Runnable() { 46 | @Override 47 | public void run() { 48 | chartView1 49 | .setHighPillarColor(new int[]{0xffff0000, 0x90ff0000}) 50 | .setCenterPillarColor(new int[]{0xff00ff00, 0x9000ff00}) 51 | .setLowPillarColor(new int[]{0xff0000ff, 0x900000ff}) 52 | .setDatumLineColor(0xffff0000) 53 | .setDottedLine(true) 54 | .setyTextUnit("min") 55 | .setPillarWidth(20)//以上子类内容,必须写在下面方法上面 56 | .isShowDatumLine_X(true) 57 | .isShowDatumLine_Y(true) 58 | .setType(BaseChartView.DAY) 59 | .setYMaxValue(250) 60 | .setUnitValueText("bpm") 61 | .refreshData(getDayData()); 62 | chartView2 63 | .setHighPillarColor(new int[]{0xffff0000, 0x90ff0000}) 64 | .setCenterPillarColor(new int[]{0xff00ff00, 0x9000ff00}) 65 | .setLowPillarColor(new int[]{0xff0000ff, 0x900000ff}) 66 | .setPillarWidth(20)//以上子类内容,必须写在下面方法上面 67 | .isShowDatumLine_X(false) 68 | .isShowDatumLine_Y(false) 69 | .setType(BaseChartView.WEEK) 70 | .setYMaxValue(250) 71 | .setUnitValueText("bpm") 72 | .refreshData(getWeekData()); 73 | chartView3 74 | .setHighPillarColor(new int[]{0xffff0000, 0x90ff0000}) 75 | .setCenterPillarColor(new int[]{0xff00ff00, 0x9000ff00}) 76 | .setLowPillarColor(new int[]{0xff0000ff, 0x900000ff}) 77 | .setPillarWidth(20)//以上子类内容,必须写在下面方法上面 78 | .isShowDatumLine_X(false) 79 | .isShowDatumLine_Y(false) 80 | .setType(BaseChartView.MONTH) 81 | .setYMaxValue(250) 82 | .setUnitValueText("bpm") 83 | .refreshData(getMonthData()); 84 | chartView4 85 | .setHighPillarColor(new int[]{0xffff0000, 0x90ff0000}) 86 | .setCenterPillarColor(new int[]{0xff00ff00, 0x9000ff00}) 87 | .setLowPillarColor(new int[]{0xff0000ff, 0x900000ff}) 88 | .setPillarWidth(20)//以上子类内容,必须写在下面方法上面 89 | .isShowDatumLine_X(false) 90 | .isShowDatumLine_Y(false) 91 | .setType(BaseChartView.YEAR) 92 | .setYMaxValue(250) 93 | .setUnitValueText("bpm") 94 | .refreshData(getYearData()); 95 | } 96 | }, 800); 97 | } 98 | 99 | private List getDayData() { 100 | //日数据源 101 | List datas1 = new ArrayList<>(); 102 | datas1.add(new BaseChartView.DataBean("2017-09-25 00:17:00", 40f, 40f+30f, 40f+30f+20f, true)); 103 | datas1.add(new BaseChartView.DataBean("2017-09-25 06:17:00", 50, 50+38, 50+38+20, true)); 104 | datas1.add(new BaseChartView.DataBean("2017-09-25 12:17:00", 50, 50+38, 50+38+20, true)); 105 | datas1.add(new BaseChartView.DataBean("2017-09-25 18:17:00", 50, 50+38, 50+38+20, false)); 106 | datas1.add(new BaseChartView.DataBean("2017-09-25 24:17:00", 92f, 92f+78f, 92f+78f+50f, true)); 107 | return datas1; 108 | } 109 | 110 | private List getWeekData() { 111 | //周数据源 112 | List datas2 = new ArrayList<>(); 113 | datas2.add(new BaseChartView.DataBean("2017-09-11 16:17:00", 40f, 40f+30f, 40f+30f+20f, true)); 114 | datas2.add(new BaseChartView.DataBean("2017-09-12 16:17:00", 50, 50+38, 50+38+20, true)); 115 | datas2.add(new BaseChartView.DataBean("2017-09-13 16:17:00", 50, 50+38, 50+38+20, true)); 116 | datas2.add(new BaseChartView.DataBean("2017-09-14 16:17:00", 50, 50+38, 50+38+20, true)); 117 | datas2.add(new BaseChartView.DataBean("2017-09-15 16:17:00", 92f, 92f+78f, 92f+78f+50f, true)); 118 | datas2.add(new BaseChartView.DataBean("2017-09-16 16:17:00", 72f, 72f+68f, 72f+68f+50f, true)); 119 | return datas2; 120 | } 121 | 122 | private List getMonthData() { 123 | //月数据源 124 | List datas3 = new ArrayList<>(); 125 | datas3.add(new BaseChartView.DataBean("2017-09-01 16:17:00", 40f, 40f+30f, 40f+30f+20f, true)); 126 | datas3.add(new BaseChartView.DataBean("2017-09-05 16:17:00", 50, 50+38, 50+38+20, true)); 127 | datas3.add(new BaseChartView.DataBean("2017-09-10 16:17:00", 50, 50+38, 50+38+20, true)); 128 | datas3.add(new BaseChartView.DataBean("2017-09-15 16:17:00", 50, 50+38, 50+38+20, true)); 129 | datas3.add(new BaseChartView.DataBean("2017-09-20 16:17:00", 92f, 92f+78f, 92f+78f+50f, true)); 130 | datas3.add(new BaseChartView.DataBean("2017-09-25 16:17:00", 72f, 72f+68f, 72f+68f+50f, true)); 131 | datas3.add(new BaseChartView.DataBean("2017-09-30 16:17:00", 72f, 72f+68f, 72f+68f+50f, true)); 132 | return datas3; 133 | } 134 | 135 | private List getYearData() { 136 | //年数据源 137 | List datas4 = new ArrayList<>(); 138 | datas4.add(new BaseChartView.DataBean("2017-01-01 16:17:00", 40f, 40f+30f, 40f+30f+20f, true)); 139 | datas4.add(new BaseChartView.DataBean("2017-02-03 16:17:00", 40f, 40f+30f, 40f+30f+20f, true)); 140 | datas4.add(new BaseChartView.DataBean("2017-03-03 16:17:00", 40f, 40f+30f, 40f+30f+20f, true)); 141 | datas4.add(new BaseChartView.DataBean("2017-06-06 16:17:00", 50, 50+38, 50+38+20, true)); 142 | datas4.add(new BaseChartView.DataBean("2017-09-09 16:17:00", 72f, 72f+68f, 72f+68f+50f, true)); 143 | datas4.add(new BaseChartView.DataBean("2017-12-12 16:17:00", 72f, 72f+68f, 72f+68f+50f, true)); 144 | return datas4; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/view/FllowerAnimation.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.view; 2 | 3 | /** 4 | * 时间:2017/8/18 5 | * 作者:黄伟才 6 | * 简书:http://www.jianshu.com/p/87e7392a16ff 7 | * github:https://github.com/huangweicai/OkLibDemo 8 | * 描述: 9 | */ 10 | 11 | import android.animation.ObjectAnimator; 12 | import android.animation.ValueAnimator; 13 | import android.content.Context; 14 | import android.graphics.Canvas; 15 | import android.graphics.Color; 16 | import android.graphics.Paint; 17 | import android.graphics.Path; 18 | import android.graphics.PathMeasure; 19 | import android.os.Build; 20 | import android.support.annotation.Nullable; 21 | import android.support.annotation.RequiresApi; 22 | import android.util.AttributeSet; 23 | import android.util.Log; 24 | import android.util.TypedValue; 25 | import android.view.View; 26 | import android.view.WindowManager; 27 | import android.view.animation.AccelerateInterpolator; 28 | 29 | import com.example.chartview.bean.Fllower; 30 | 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | import java.util.Random; 34 | 35 | /** 36 | 37 | */ 38 | 39 | /** 40 | * 时间:2017/8/18 41 | * 作者:黄伟才 42 | * 简书:http://www.jianshu.com/p/87e7392a16ff 43 | * github:https://github.com/huangweicai/OkLibDemo 44 | * 描述:撒花 45 | * 用到的知识点: 46 | * 1、android属性动画 47 | * 2、Path路径绘制 48 | * 3、贝塞尔曲线 49 | */ 50 | public class FllowerAnimation extends View implements ValueAnimator.AnimatorUpdateListener { 51 | 52 | /** 53 | * 动画改变的属性值 54 | */ 55 | private float phase1 = 0f; 56 | private float phase2 = 0f; 57 | private float phase3 = 0f; 58 | 59 | /** 60 | * 小球集合 61 | */ 62 | private List fllowers1 = new ArrayList(); 63 | private List fllowers2 = new ArrayList(); 64 | private List fllowers3 = new ArrayList(); 65 | 66 | /** 67 | * 动画播放的时间 68 | */ 69 | private int time = 4000; 70 | /** 71 | * 动画间隔 72 | */ 73 | private int delay = 500; 74 | 75 | public FllowerAnimation(Context context) { 76 | super(context); 77 | init(context); 78 | } 79 | 80 | public FllowerAnimation(Context context, @Nullable AttributeSet attrs) { 81 | super(context, attrs); 82 | init(context); 83 | } 84 | 85 | public FllowerAnimation(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 86 | super(context, attrs, defStyleAttr); 87 | init(context); 88 | } 89 | 90 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 91 | public FllowerAnimation(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 92 | super(context, attrs, defStyleAttr, defStyleRes); 93 | init(context); 94 | } 95 | 96 | private void init(Context context) { 97 | WindowManager wm = (WindowManager) context 98 | .getSystemService(Context.WINDOW_SERVICE); 99 | width = wm.getDefaultDisplay().getWidth(); 100 | height = (int) (wm.getDefaultDisplay().getHeight() * 3 / 2f); 101 | 102 | mPaint = new Paint(); 103 | mPaint.setAntiAlias(true); 104 | mPaint.setStrokeWidth(2); 105 | mPaint.setColor(Color.BLUE); 106 | mPaint.setStyle(Paint.Style.STROKE); 107 | 108 | pathMeasure = new PathMeasure(); 109 | 110 | builderFollower(fllowerCount, fllowers1); 111 | builderFollower(fllowerCount, fllowers2); 112 | builderFollower(fllowerCount, fllowers3); 113 | 114 | } 115 | 116 | /** 117 | * 宽度 118 | */ 119 | private int width = 0; 120 | /** 121 | * 高度 122 | */ 123 | private int height = 0; 124 | 125 | /** 126 | * 曲线高度个数分割 127 | */ 128 | private int quadCount = 10; 129 | /** 130 | * 曲度 131 | */ 132 | private float intensity = 0.2f; 133 | 134 | /** 135 | * 第一批个数 136 | */ 137 | private int fllowerCount = 4; 138 | 139 | /** 140 | * 创建花 141 | */ 142 | private void builderFollower(int count, List fllowers) { 143 | int max = (int) (width * 3 / 4f); 144 | int min = (int) (width / 4f); 145 | Random random = new Random(); 146 | for (int i = 0; i < count; i++) { 147 | int s = random.nextInt(max) % (max - min + 1) + min; 148 | Path path = new Path(); 149 | CPoint CPoint = new CPoint(s, 0); 150 | List points = builderPath(CPoint); 151 | drawFllowerPath(path, points); 152 | Fllower fllower = new Fllower(); 153 | fllower.setPath(path); 154 | fllowers.add(fllower); 155 | } 156 | 157 | } 158 | 159 | /** 160 | * 画曲线 161 | * 162 | * @param path 163 | * @param points 164 | */ 165 | private void drawFllowerPath(Path path, List points) { 166 | if (points.size() > 1) { 167 | for (int j = 0; j < points.size(); j++) { 168 | 169 | CPoint point = points.get(j); 170 | 171 | if (j == 0) { 172 | CPoint next = points.get(j + 1); 173 | point.dx = ((next.x - point.x) * intensity); 174 | point.dy = ((next.y - point.y) * intensity); 175 | } else if (j == points.size() - 1) { 176 | CPoint prev = points.get(j - 1); 177 | point.dx = ((point.x - prev.x) * intensity); 178 | point.dy = ((point.y - prev.y) * intensity); 179 | } else { 180 | CPoint next = points.get(j + 1); 181 | CPoint prev = points.get(j - 1); 182 | point.dx = ((next.x - prev.x) * intensity); 183 | point.dy = ((next.y - prev.y) * intensity); 184 | } 185 | 186 | // create the cubic-spline path 187 | if (j == 0) { 188 | path.moveTo(point.x, point.y); 189 | } else { 190 | CPoint prev = points.get(j - 1); 191 | path.cubicTo(prev.x + prev.dx, (prev.y + prev.dy), 192 | point.x - point.dx, (point.y - point.dy), 193 | point.x, point.y); 194 | } 195 | } 196 | } 197 | } 198 | 199 | /** 200 | * 曲线摇摆的幅度 201 | */ 202 | private int range = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, getResources().getDisplayMetrics()); 203 | 204 | /** 205 | * 画路径 206 | * 207 | * @param point 208 | * @return 209 | */ 210 | private List builderPath(CPoint point) { 211 | List points = new ArrayList(); 212 | Random random = new Random(); 213 | for (int i = 0; i < quadCount; i++) { 214 | if (i == 0) { 215 | points.add(point); 216 | } else { 217 | CPoint tmp = new CPoint(0, 0); 218 | if (random.nextInt(100) % 2 == 0) { 219 | tmp.x = point.x + random.nextInt(range); 220 | } else { 221 | tmp.x = point.x - random.nextInt(range); 222 | } 223 | tmp.y = (int) (height / (float) quadCount * i); 224 | points.add(tmp); 225 | } 226 | } 227 | return points; 228 | } 229 | 230 | /** 231 | * 画笔 232 | */ 233 | private Paint mPaint; 234 | 235 | /** 236 | * 测量路径的坐标位置 237 | */ 238 | private PathMeasure pathMeasure = null; 239 | 240 | @Override 241 | protected void onDraw(Canvas canvas) { 242 | super.onDraw(canvas); 243 | 244 | drawFllower(canvas, fllowers1); 245 | drawFllower(canvas, fllowers2); 246 | drawFllower(canvas, fllowers3); 247 | 248 | } 249 | 250 | /** 251 | * 高度往上偏移量,把开始点移出屏幕顶部 252 | */ 253 | private float dy = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()); 254 | 255 | /** 256 | * @param canvas 257 | * @param fllowers 258 | */ 259 | private void drawFllower(Canvas canvas, List fllowers) { 260 | for (Fllower fllower : fllowers) { 261 | float[] pos = new float[2]; 262 | canvas.drawPath(fllower.getPath(), mPaint); 263 | pathMeasure.setPath(fllower.getPath(), false); 264 | pathMeasure.getPosTan(height * fllower.getValue(), pos, null); 265 | canvas.drawCircle(pos[0], pos[1], 10, mPaint); 266 | 267 | //Log.d("TAG", "x:"+pos[0]+" y:"+pos[1]); 268 | Log.d("TAG", "height:"+height+" getValue:"+fllower.getValue());//y一直为0 269 | 270 | // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.app_icon); 271 | // canvas.drawBitmap(bitmap, pos[0], pos[1] - dy, null); 272 | // bitmap.recycle(); 273 | } 274 | } 275 | 276 | public void startAnimation() { 277 | ObjectAnimator mAnimator1 = ObjectAnimator.ofFloat(this, "phase1", 0f, 278 | 1f); 279 | mAnimator1.setDuration(time); 280 | mAnimator1.addUpdateListener(this); 281 | mAnimator1.start(); 282 | mAnimator1.setInterpolator(new AccelerateInterpolator(1f)); 283 | 284 | ObjectAnimator mAnimator2 = ObjectAnimator.ofFloat(this, "phase2", 0f, 285 | 1f); 286 | mAnimator2.setDuration(time); 287 | mAnimator2.addUpdateListener(this); 288 | mAnimator2.start(); 289 | mAnimator2.setInterpolator(new AccelerateInterpolator(1f)); 290 | mAnimator2.setStartDelay(delay); 291 | 292 | ObjectAnimator mAnimator3 = ObjectAnimator.ofFloat(this, "phase3", 0f, 293 | 1f); 294 | mAnimator3.setDuration(time); 295 | mAnimator3.addUpdateListener(this); 296 | mAnimator3.start(); 297 | mAnimator3.setInterpolator(new AccelerateInterpolator(1f)); 298 | mAnimator3.setStartDelay(delay * 2); 299 | } 300 | 301 | /** 302 | * 跟新小球的位置 303 | * 304 | * @param value 305 | * @param fllowers 306 | */ 307 | private void updateValue(float value, List fllowers) { 308 | for (Fllower fllower : fllowers) { 309 | fllower.setValue(value); 310 | } 311 | } 312 | 313 | /** 314 | * 动画改变回调 315 | */ 316 | @Override 317 | public void onAnimationUpdate(ValueAnimator arg0) { 318 | updateValue(getPhase1(), fllowers1); 319 | updateValue(getPhase2(), fllowers2); 320 | updateValue(getPhase3(), fllowers3); 321 | //Log.i(tag, getPhase1() + ""); 322 | invalidate(); 323 | } 324 | 325 | public float getPhase1() { 326 | return phase1; 327 | } 328 | 329 | public void setPhase1(float phase1) { 330 | this.phase1 = phase1; 331 | } 332 | 333 | public float getPhase2() { 334 | return phase2; 335 | } 336 | 337 | public void setPhase2(float phase2) { 338 | this.phase2 = phase2; 339 | } 340 | 341 | public float getPhase3() { 342 | return phase3; 343 | } 344 | 345 | public void setPhase3(float phase3) { 346 | this.phase3 = phase3; 347 | } 348 | 349 | private String tag = this.getClass().getSimpleName(); 350 | 351 | private class CPoint { 352 | 353 | public float x = 0f; 354 | public float y = 0f; 355 | 356 | /** 357 | * x-axis distance 358 | */ 359 | public float dx = 0f; 360 | 361 | /** 362 | * y-axis distance 363 | */ 364 | public float dy = 0f; 365 | 366 | public CPoint(float x, float y) { 367 | this.x = x; 368 | this.y = y; 369 | } 370 | } 371 | 372 | } 373 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/chartview/view/MyView.java: -------------------------------------------------------------------------------- 1 | package com.example.chartview.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.DashPathEffect; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | 14 | import com.example.chartview.R; 15 | 16 | /** 17 | * 时间:2017/9/25 18 | * 作者:黄伟才 19 | * 描述: 20 | */ 21 | 22 | public class MyView extends View { 23 | /** 24 | * 中央分割线的绘制 25 | **/ 26 | private Paint linePaint; 27 | private Paint strockpaint; 28 | private Paint p; 29 | private Bitmap decodeResource; 30 | 31 | public MyView(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | linePaint = new Paint(); 34 | linePaint.setAntiAlias(true); 35 | // linePaint.setColor(Color.parseColor("#aeaeae")); 36 | linePaint.setColor(Color.RED); 37 | linePaint.setStrokeWidth(2f); 38 | linePaint.setTextSize(25); 39 | linePaint.setStrokeJoin(Paint.Join.ROUND); 40 | 41 | 42 | strockpaint = new Paint(); 43 | strockpaint.setAntiAlias(true); 44 | strockpaint.setStyle(Paint.Style.STROKE); 45 | strockpaint.setColor(Color.BLUE); 46 | DashPathEffect effects = new DashPathEffect(new float[]{5, 5, 5, 5}, 1); 47 | strockpaint.setPathEffect(effects); 48 | 49 | p = new Paint(Paint.ANTI_ALIAS_FLAG); 50 | p.setStyle(Paint.Style.STROKE); 51 | p.setColor(Color.RED); 52 | p.setStrokeWidth(1); 53 | p.setTextSize(30); 54 | p.setStrokeWidth(10); 55 | 56 | DashPathEffect effects1 = new DashPathEffect(new float[]{1, 4, 7, 8}, 1); 57 | p.setPathEffect(effects1); 58 | decodeResource = BitmapFactory.decodeResource(getResources(), R.drawable.exchange_icon); 59 | } 60 | 61 | @Override 62 | protected void onDraw(Canvas canvas) { 63 | super.onDraw(canvas); 64 | canvas.drawLine(100, 0, 600, 1000, linePaint); 65 | 66 | canvas.drawCircle(202, 202, 100, strockpaint); 67 | canvas.drawLine(0, 0, 400, 400, strockpaint); 68 | canvas.drawRect(20, 100, 21, 450, strockpaint); 69 | 70 | 71 | canvas.drawText("绘制红色的虚线", 210, 300, linePaint); 72 | canvas.drawLine(200, 140, 500, 40, p); 73 | //绘制红色的虚线 74 | Path path = new Path(); 75 | path.moveTo(200, 300); 76 | path.lineTo(300, 1600); 77 | canvas.drawPath(path, p); 78 | canvas.drawBitmap(createRepeaterY(1000, decodeResource), 300, 300, null); 79 | } 80 | 81 | //绘制重复bitmap的图片 82 | public Bitmap createRepeaterY(int height, Bitmap src) { 83 | int count = (height + src.getHeight() - 1) / src.getHeight(); 84 | Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), height, Bitmap.Config.ARGB_8888); 85 | Canvas canvas = new Canvas(bitmap); 86 | for (int idx = 0; idx < count; ++idx) { 87 | canvas.drawBitmap(src, 0, idx * src.getHeight(), null); 88 | } 89 | return bitmap; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/exchange_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangweicai/ChartView/aa6aa5ba9bf9483d79b7619c6a2f9e7953e25859/app/src/main/res/drawable/exchange_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/round_white_alpha.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_fllower_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 |