#ZqxChart maven:
com.zqx.chart
chart
0.2
pom
gradle:
compile 'com.zqx.chart:chart:0.2'
使用方法:
1.折线图
//通过代码设置:
LineChart lineChart = (LineChart) findViewById(R.id.linechart);
LineChartData lineChartData = LineChartData.builder()
.setXdata(xdata)//x轴数据
.setYdata(ydata)//y轴数据
.setYpCount(7)//y轴刻度数量
.setCoordinatesColor(getResources().getColor(android.R.color.holo_orange_dark))
//.setXXX()
.setAnimType(Anim.ANIM_ALPHA)//动画效果,目前仅支持两种
.build();
lineChart.setChartData(lineChartData);
//通过xml设置:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:chart="http://schemas.android.com/apk/res/com.zqx.zqxcharts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_marginTop="5dp"
android:id="@+id/linechart"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="5dp"
chart:lCoordinatesColor="@color/colorAccent"
chart:lxTextColor="@color/colorAccent"
chart:lyTextColor="@color/colorAccent"
chart:pointColor="@color/colorAccent"
/>
// res/下新建 attrs.xml
2.柱状图
//通过代码设置
Histogram histogramChart = (Histogram) findViewById(R.id.histogramchart);
HistogramData histogramData = HistogramData.builder()
.setXdata(xdata)
.setYdata(ydata)
.setYpCount(7)
.setAnimType(Anim.ANIM_ALPHA)
.build();
histogramChart.setChartData(histogramData);
#通过xml设置
android:layout_marginTop="5dp"
android:id="@+id/linechart"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="5dp"
chart:lCoordinatesColor="@color/colorAccent"
chart:lxTextColor="@color/colorAccent"
chart:lyTextColor="@color/colorAccent"
chart:pointColor="@color/colorAccent"
/>
//也可以通过代码和 arrays.xml 设置每个x坐标对应柱状图的颜色,代码可以通过新建一个color 数组并调用
setColors(xxx);
//arrays.xml color 个数与数据个数对应
@android:color/darker_gray
@android:color/holo_red_dark
@android:color/holo_green_dark
@android:color/holo_orange_dark
@color/histogram_test
@android:color/holo_blue_dark
@color/colorAccent
3.饼状图
饼状图动画效果目前只支持alpha
code:
PieChart pieChart = (PieChart) findViewById(R.id.piechart);
int[] colors = new int[]{Color.RED,Color.BLACK,Color.BLUE,Color.GREEN,Color.GRAY,
Color.YELLOW,Color.LTGRAY,Color.CYAN,Color.MAGENTA};
PieChartData pieChartData = PieChartData.builder()
.setDatas(datas)
//.setColors(colors)
.setTextColor(Color.RED)
//.setTextSize(36)
//.setSeparationDegree(3)
.setPieItemClickListener(new OnPieItemClickListener() {
@Override
public void onPieItemClick(int position) {
Toast.makeText(MainActivity.this,"click->"+position,Toast.LENGTH_SHORT).show();
}
}).build();
pieChart.setChartData(pieChartData);
xml:
android:id="@+id/piechart"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="400dp"
chart:textColor="@color/colorAccent"
chart:textSize="40"
/>
@color/colorPrimary
@android:color/darker_gray
@android:color/holo_red_dark
@android:color/holo_green_dark
@android:color/holo_orange_dark
@android:color/white
@android:color/holo_blue_dark
@color/colorAccent
@android:color/black
饼状图自定义属性
待完成
折线图和柱状图的多组数据显示。