use of com.github.mikephil.charting.data.PieData in project HAR-Android by linw7.
the class PieActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pie);
pie_chart = (PieChart) findViewById(R.id.pie_chart);
PieData pie_data = get_pie_data();
show_pie_chart(pie_chart, pie_data);
}
use of com.github.mikephil.charting.data.PieData in project Dxditor by kimi2009.
the class MainActivity method setGjxxData.
/**
* 设置告警信息的数据
*
* @param gjxxlist
*/
@Override
public void setGjxxData(List<GjxxBean> gjxxlist) {
ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
// the chart.
for (int i = 0; i < gjxxlist.size(); i++) {
entries.add(new PieEntry(gjxxlist.get(i).getTypeProportion() * 100, gjxxlist.get(i).getTypeName()));
}
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setDrawIcons(false);
dataSet.setSliceSpace(3f);
dataSet.setIconsOffset(new MPPointF(0, 40));
dataSet.setSelectionShift(5f);
// add a lot of colors
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS) colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS) colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
// 26个颜色
dataSet.setColors(colors);
// dataSet.setSelectionShift(0f);
dataSet.setValueLinePart1OffsetPercentage(80.f);
dataSet.setValueLinePart1Length(0.2f);
dataSet.setValueLinePart2Length(0.4f);
// dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
PieData data = new PieData(dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.BLACK);
gjpiechart.setData(data);
// undo all highlights
gjpiechart.highlightValues(null);
gjpiechart.invalidate();
}
use of com.github.mikephil.charting.data.PieData in project MPAndroidChart by PhilJay.
the class ListViewMultiChartActivity method generateDataPie.
/**
* generates a random ChartData object with just one DataSet
*
* @return Pie data
*/
private PieData generateDataPie() {
ArrayList<PieEntry> entries = new ArrayList<>();
for (int i = 0; i < 4; i++) {
entries.add(new PieEntry((float) ((Math.random() * 70) + 30), "Quarter " + (i + 1)));
}
PieDataSet d = new PieDataSet(entries, "");
// space between slices
d.setSliceSpace(2f);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
return new PieData(d);
}
use of com.github.mikephil.charting.data.PieData in project MPAndroidChart by PhilJay.
the class PiePolylineChartActivity method setData.
private void setData(int count, float range) {
ArrayList<PieEntry> entries = new ArrayList<>();
// the chart.
for (int i = 0; i < count; i++) {
entries.add(new PieEntry((float) (Math.random() * range) + range / 5, parties[i % parties.length]));
}
PieDataSet dataSet = new PieDataSet(entries, "Election Results");
dataSet.setSliceSpace(3f);
dataSet.setSelectionShift(5f);
// add a lot of colors
ArrayList<Integer> colors = new ArrayList<>();
for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS) colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS) colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
// dataSet.setSelectionShift(0f);
dataSet.setValueLinePart1OffsetPercentage(80.f);
dataSet.setValueLinePart1Length(0.2f);
dataSet.setValueLinePart2Length(0.4f);
// dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
PieData data = new PieData(dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.BLACK);
data.setValueTypeface(tf);
chart.setData(data);
// undo all highlights
chart.highlightValues(null);
chart.invalidate();
}
use of com.github.mikephil.charting.data.PieData in project MPAndroidChart by PhilJay.
the class PieChartRenderer method drawData.
@Override
public void drawData(Canvas c) {
int width = (int) mViewPortHandler.getChartWidth();
int height = (int) mViewPortHandler.getChartHeight();
Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get();
if (drawBitmap == null || (drawBitmap.getWidth() != width) || (drawBitmap.getHeight() != height)) {
if (width > 0 && height > 0) {
drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
mDrawBitmap = new WeakReference<>(drawBitmap);
mBitmapCanvas = new Canvas(drawBitmap);
} else
return;
}
drawBitmap.eraseColor(Color.TRANSPARENT);
PieData pieData = mChart.getData();
for (IPieDataSet set : pieData.getDataSets()) {
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
Aggregations