使用数据库生成android饼图
有人能给我推荐最好的教程或示例代码来生成带有数据库值的饼图吗?我已经访问了MPAndroidChart文档,但仍然很混乱。谢谢 我使用MPAndroid的饼图来显示出勤情况使用数据库生成android饼图,android,sqlite,pie-chart,Android,Sqlite,Pie Chart,有人能给我推荐最好的教程或示例代码来生成带有数据库值的饼图吗?我已经访问了MPAndroidChart文档,但仍然很混乱。谢谢 我使用MPAndroid的饼图来显示出勤情况 Add the following to your project level build.gradle: allprojects { repositories { maven { url "https://jitpack.io" } } } Add this to your ap
Add the following to your project level build.gradle:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Add this to your app build.gradle:
dependencies {
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
}
下面是Java代码
piechart.setPressed(false);
PieChartAttention.setUsePercentValues(真);
piechart.setRotationEnabled(false);
皮耶沙特·塞托雷拉迪乌斯(0);
piechart.setDescription(“”);
Piechart.animateXY(10001000);
piechart.setDrawHoleEnabled(false);
piechart.invalidate();
Legend pieLegend=PieChartAttention.getLegend();
pieLegend.setEnabled(false);
ArrayList ArrayList=新的ArrayList();
ArrayList arrayListXAxis=新的ArrayList();
//出席率
浮动出席百分比=(出席人数*100)/总出席人数;
浮动缺席百分比=(缺席人数*100)/总出勤率;
添加(新条目(presentPercentage,0));
添加(新条目(absentPercentage,1));
arrayListXAxis.添加(“当前”);
arrayListXAxis.add(“缺席”);
PieDataSet数据集=新的PieDataSet(arrayList,“”);
dataSet.setLiceSpace(2);
dataSet.setSelectionShift(2);
//彩色阵列
ArrayList colors=新的ArrayList();
添加(Color.rgb(7617580));
添加(Color.rgb(244,67,54));
dataSet.setColors(颜色);
PieData PieData=新PieData(arrayListXAxis,数据集);
setValueFormatter(新的PercentFormatter());
piedata.setValueTextSize(11f);
piedata.setValueTextColor(Color.WHITE);
piechart.setData(piedata);
Xml代码
请参见此。。。在这里,您的表名是存在和不存在的,对吗?事实上,我还有两张表,比如收入和支出,但我想在饼图中得到准确的信息,比如租金xxx,薪水xxx,你提到了两张,但我想要n张,因为这取决于用户。你能帮我吗?如果是,我欠你一杯啤酒;)添加(新条目(presentPercentage,0));添加(新条目(absentPercentage,1));arrayList.add(新条目(xxx_百分比,2));arrayList.add(新条目(yyy_百分比,3))arrayList.add(“xxx”);arrayListXAxis.add(“yyy”);颜色。添加(xxx的颜色);添加(yyy的颜色);
pieChartAttendance.setPressed(false);
pieChartAttendance.setUsePercentValues(true);
pieChartAttendance.setRotationEnabled(false);
pieChartAttendance.setHoleRadius(0);
pieChartAttendance.setDescription("");
pieChartAttendance.animateXY(1000, 1000);
pieChartAttendance.setDrawHoleEnabled(false);
pieChartAttendance.invalidate();
Legend pieLegend = pieChartAttendance.getLegend();
pieLegend.setEnabled(false);
ArrayList<Entry> arrayList = new ArrayList<Entry>();
ArrayList<String> arrayListXAxis = new ArrayList<String>();
//Percentage of Attendance
float presentPercentage = (presentCount * 100) / totalAttendance;
float absentPercentage = (absentCount * 100) / totalAttendance;
arrayList.add(new Entry(presentPercentage, 0));
arrayList.add(new Entry(absentPercentage, 1));
arrayListXAxis.add("Present");
arrayListXAxis.add("Absent");
PieDataSet dataSet = new PieDataSet(arrayList, "");
dataSet.setSliceSpace(2);
dataSet.setSelectionShift(2);
//Color Array
ArrayList<Integer> colors = new ArrayList<Integer>();
colors.add(Color.rgb(76, 175, 80));
colors.add(Color.rgb(244, 67, 54));
dataSet.setColors(colors);
PieData piedata = new PieData(arrayListXAxis, dataSet);
piedata.setValueFormatter(new PercentFormatter());
piedata.setValueTextSize(11f);
piedata.setValueTextColor(Color.WHITE);
pieChartAttendance.setData(piedata);
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pieChartAttendance"
android:layout_width="120dp"
android:layout_height="120dp"
/>