Search in sources :

Example 6 with PercentFormatter

use of com.github.mikephil.charting.formatter.PercentFormatter in project MPAndroidChart by PhilJay.

the class PieChartItem method getView.

@Override
public View getView(int position, View convertView, Context c) {
    ViewHolder holder = null;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(c).inflate(R.layout.list_item_piechart, null);
        holder.chart = (PieChart) convertView.findViewById(R.id.chart);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    // apply styling
    holder.chart.getDescription().setEnabled(false);
    holder.chart.setHoleRadius(52f);
    holder.chart.setTransparentCircleRadius(57f);
    holder.chart.setCenterText(mCenterText);
    holder.chart.setCenterTextTypeface(mTf);
    holder.chart.setCenterTextSize(9f);
    holder.chart.setUsePercentValues(true);
    holder.chart.setExtraOffsets(5, 10, 50, 10);
    mChartData.setValueFormatter(new PercentFormatter());
    mChartData.setValueTypeface(mTf);
    mChartData.setValueTextSize(11f);
    mChartData.setValueTextColor(Color.WHITE);
    // set data
    holder.chart.setData((PieData) mChartData);
    Legend l = holder.chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);
    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateY(900);
    return convertView;
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) Legend(com.github.mikephil.charting.components.Legend)

Aggregations

PercentFormatter (com.github.mikephil.charting.formatter.PercentFormatter)6 PieData (com.github.mikephil.charting.data.PieData)3 PieDataSet (com.github.mikephil.charting.data.PieDataSet)3 PieEntry (com.github.mikephil.charting.data.PieEntry)3 ArrayList (java.util.ArrayList)3 Point (android.graphics.Point)1 BarLineChartBase (com.github.mikephil.charting.charts.BarLineChartBase)1 Legend (com.github.mikephil.charting.components.Legend)1 XAxis (com.github.mikephil.charting.components.XAxis)1 YAxis (com.github.mikephil.charting.components.YAxis)1 MPPointF (com.github.mikephil.charting.utils.MPPointF)1