标签:
该库的可扩展性强,代码相对规范,最近一次更新有很大改进,如果不喜欢AChartEngine的过于复杂可以考虑在此库的基础上开发自己的图表类。
linechart

填充式lineChart

单条线的LineChart

BarChart2D



BarChart3D

PieChart


ScatterChart

以piechart为例介绍使用方法:
xml中
|
1
2
3
4
|
<com.github.mikephil.charting.charts.PieChart android:id="@+id/spread_pie_chart" android:layout_width="match_parent" android:layout_height="320dip" /> |
activity中
初始化
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
ColorTemplate mCt; mCt = new ColorTemplate(); mCt.addDataSetColors(ColorTemplate.PASTEL_COLORS, this); mChart = (PieChart) headView.findViewById(R.id.spread_pie_chart); mChart.setColorTemplate(mCt); mChart.setDescription(""); mChart.setHoleRadius(30f); mChart.setTransparentCircleRadius(0f); mChart.setCenterTextSize(18f); mChart.setDrawXValues(true); mChart.setUsePercentValues(true); mChart.setDrawLegend(false); // space between slices mChart.setSliceSpace(1f); mChart.setDrawHoleEnabled(false); mChart.setTouchEnabled(false); |
数据
|
1
2
3
4
5
6
7
8
9
10
11
|
ArrayList<Entry> yVals = new ArrayList<Entry>();ArrayList<String> xVals = new ArrayList<String>();for (int i = 0; i < listDatas.size(); i++) { yVals.add(new Entry((float)listDatas.get(i).getProvinceCount(), i)); xVals.add(listDatas.get(i).getProvinceName());}DataSet set1 = new DataSet(yVals, "Content");ArrayList<DataSet> dataSets = new ArrayList<DataSet>();dataSets.add(set1);ChartData data = new ChartData(xVals, dataSets);mChart.setData(data); |
其中listData为自己项目中的数据源。
标签:
原文地址:http://www.cnblogs.com/jiayonghua/p/5106165.html