在项目的gradle文件中,增加compile 'wellijohn.org.simplelinechart:linechart:0.0.2'
一.线性图表的实现
使用example:
1.初始化数据:
//y轴的点
private double[] mYdots = new double[]{0, 5, 10, 15, 20, 25, 30, 35, 40};
//x轴的点
private String[] mXdots = new String[]{"08/18", "08/19", "08/20", "08/21", "08/22", "08/23",
"08/24","08/25", "08/26", "08/27", "08/28", "08/29", "09/01", "09/02", "09/23"};
//在布局中写的ChartLine
<wellijohn.org.linechart.chartline.ChartLine
android:id="@+id/chartLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
private ChartLine mChartLine;
//显示的坐标点,通过这些坐标点进行连线
private List mListDisDots;
//构造显示的点数据
private void initTestData() {
mListDisDots = new ArrayList<>();
DotVo tempDotVo = new DotVo("08/18", 5);
mListDisDots.add(tempDotVo);
DotVo tempDotVo1 = new DotVo("08/19", 10);
mListDisDots.add(tempDotVo1);
DotVo tempDotVo2 = new DotVo("08/20", 7);
mListDisDots.add(tempDotVo2);
DotVo tempDotVo3 = new DotVo("08/21", 15);
mListDisDots.add(tempDotVo3);
DotVo tempDotVo4 = new DotVo("08/22", 23);
mListDisDots.add(tempDotVo4);
DotVo tempDotVo5 = new DotVo("08/23", 40);
mListDisDots.add(tempDotVo5);
DotVo tempDotVo6 = new DotVo("09/02", 0);
mListDisDots.add(tempDotVo6);
}
2.设置数据,并显示
try {
mChartLine.setYdots(mYdots).setXdots(mXdots).setListDisDots(mListDisDots).reDraw();
} catch (YCoordinateException e) {
e.printStackTrace();
}
使用example:
1.初始化数据:
//在布局中写的CirclePercentChart
<wellijohn.org.simplelinechart.circlepercentchart.CirclePercentChart
android:id="@+id/circle_percent_chart"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true" />
private CirclePercentChart mCirclePercentChart;
构造数据:
private void initTestData() {
mListDisArcs = new ArrayList<>();
ArcVo tempDotVo = new ArcVo(Color.RED, .42f);
mListDisArcs.add(tempDotVo);
ArcVo tempDotVo1 = new ArcVo(Color.YELLOW, .38f);
mListDisArcs.add(tempDotVo1);
ArcVo tempDotVo2 = new ArcVo(Color.GREEN, .09f);
mListDisArcs.add(tempDotVo2);
ArcVo tempDotVo3 = new ArcVo(Color.BLACK, .05f);
mListDisArcs.add(tempDotVo3);
ArcVo tempDotVo4 = new ArcVo(Color.BLUE, .06f);
mListDisArcs.add(tempDotVo4);
}
2.设置数据,并显示
try {
mCirclePercentChart.setDisArcList(mListDisArcs).reDraw();
} catch (PercentOverFlowException e) {
e.printStackTrace();
}