图表使用指南

本项目图表的绘制均采用Github开源库MPAndroidChart。
github地址:MPAndroidchart

折线图

首先,设置图表样式

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
LineChart mLineChart = (LineChart) findViewById(R.id.chart);
// 弹出的数据点提示框。
MarkerView mv = new MyMarkerView(this, R.layout.marker_view);
chart.setMarkerView(mv);
// 触摸
mLineChart.setTouchEnabled(true);
// 拖拽
mLineChart.setDragEnabled(true);
// 缩放
mLineChart.setScaleEnabled(true);
mLineChart.setPinchZoom(false);
// 比例图标,y的value
Legend mLegend = mLineChart.getLegend();
mLegend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); mLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
mLegend.setOrientation(Legend.LegendOrientation.VERTICAL);
mLegend.setDrawInside(false);
//不显示比例图标
//mLegend.setEnabled(false);
mLegend.setEnabled(true);
//不显示背景网格
mLineChart.setDrawGridBackground(false);

然后,设置数据

1
2
// 不要在折线上标出数据。
mLineData.setDrawValues(false);
如果您觉得这篇文章不错,可以打赏支持下哦,谢谢