use of com.github.mikephil.charting.data.PieDataSet in project carat by amplab.
the class Chart method prepareLegend.
/**
* Generates an automatically prepared legend depending on the DataSets in
* the chart and their colors.
*/
public void prepareLegend() {
ArrayList<String> labels = new ArrayList<String>();
ArrayList<Integer> colors = new ArrayList<Integer>();
// loop for building up the colors and labels used in the legend
for (int i = 0; i < mData.getDataSetCount(); i++) {
DataSet<? extends Entry> dataSet = mData.getDataSetByIndex(i);
ArrayList<Integer> clrs = dataSet.getColors();
int entryCount = dataSet.getEntryCount();
// if we have a barchart with stacked bars
if (dataSet instanceof BarDataSet && ((BarDataSet) dataSet).getStackSize() > 1) {
BarDataSet bds = (BarDataSet) dataSet;
String[] sLabels = bds.getStackLabels();
for (int j = 0; j < clrs.size() && j < entryCount && j < bds.getStackSize(); j++) {
labels.add(sLabels[j % sLabels.length]);
colors.add(clrs.get(j));
}
// add the legend description label
colors.add(-2);
labels.add(bds.getLabel());
} else if (dataSet instanceof PieDataSet) {
ArrayList<String> xVals = mData.getXVals();
PieDataSet pds = (PieDataSet) dataSet;
for (int j = 0; j < clrs.size() && j < entryCount && j < xVals.size(); j++) {
labels.add(xVals.get(j));
colors.add(clrs.get(j));
}
// add the legend description label
colors.add(-2);
labels.add(pds.getLabel());
} else {
for (int j = 0; j < clrs.size() && j < entryCount; j++) {
// if multiple colors are set for a DataSet, group them
if (j < clrs.size() - 1 && j < entryCount - 1) {
labels.add(null);
} else {
// add label to the last entry
String label = mData.getDataSetByIndex(i).getLabel();
labels.add(label);
}
colors.add(clrs.get(j));
}
}
}
Legend l = new Legend(colors, labels);
if (mLegend != null) {
// apply the old legend settings to a potential new legend
l.apply(mLegend);
}
mLegend = l;
}
use of com.github.mikephil.charting.data.PieDataSet in project anitrend-app by AniTrend.
the class MediaStatsFragment method showStatusDistribution.
private void showStatusDistribution() {
if (model.getStats() != null && model.getStats().getStatusDistribution() != null) {
configureSeriesStats();
List<PieEntry> pieEntries = getPresenter().getMediaStats(model.getStats().getStatusDistribution());
PieDataSet pieDataSet = new PieDataSet(pieEntries, getString(R.string.title_series_stats));
pieDataSet.setSliceSpace(3f);
pieDataSet.setColors(Color.parseColor("#6fc1ea"), Color.parseColor("#48c76d"), Color.parseColor("#f7464a"), Color.parseColor("#46bfbd"), Color.parseColor("#fba640"));
PieData pieData = new PieData(pieDataSet);
pieData.setValueTextColor(CompatUtil.getColorFromAttr(getContext(), R.attr.titleColor));
pieData.setValueTextSize(10f);
pieData.setValueFormatter(new PercentFormatter());
binding.seriesStats.setData(pieData);
binding.seriesStats.highlightValues(null);
binding.seriesStats.invalidate();
}
}
use of com.github.mikephil.charting.data.PieDataSet in project HAR-Android by linw7.
the class PieActivity method get_pie_data.
private PieData get_pie_data() {
// xVals用来表示每个饼块上的内容
ArrayList<String> xValues = new ArrayList<String>();
xValues.add("静坐");
xValues.add("站立");
xValues.add("上楼");
xValues.add("下楼");
xValues.add("步行");
xValues.add("慢跑");
// yVals用来表示封装每个饼块的实际数据
ArrayList<Entry> yValues = new ArrayList<Entry>();
yValues.add(new Entry(sit, 0));
yValues.add(new Entry(stand, 1));
yValues.add(new Entry(upstairs, 2));
yValues.add(new Entry(downstairs, 3));
yValues.add(new Entry(walk, 4));
yValues.add(new Entry(jog, 5));
ArrayList<Integer> colors = new ArrayList<Integer>();
colors.add(Color.rgb(0, 245, 255));
colors.add(Color.rgb(131, 111, 255));
colors.add(Color.rgb(192, 255, 62));
colors.add(Color.rgb(255, 160, 122));
colors.add(Color.rgb(255, 187, 255));
colors.add(Color.rgb(155, 241, 226));
PieDataSet pieDataSet = new PieDataSet(yValues, "");
pieDataSet.setColors(colors);
pieDataSet.setValueTextSize(10);
DisplayMetrics metrics = getResources().getDisplayMetrics();
float px = 5 * (metrics.densityDpi / 160f);
pieDataSet.setSelectionShift(px);
PieData pieData = new PieData(xValues, pieDataSet);
return pieData;
}
Aggregations