//========================================
public class PieChartView extends View{
private final static String[] RColors = {"#448c9b", "#789a98", "#a4a795", "#ac6226", "#ef3c5e", "#b17170", "#9a9a82", "#bda763"};
private RectF rec;
private Paint p = new Paint();
private String[][] data = {
{"Facebook", "20"},
{"Twitter", "20"},
{"Whats app", "20"},
{"Pinterest", "20"},
{"Baby App", "20"}
};
private int d = 0;
private float textSize = 20f;
//========================
public PieChartView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//========================
public PieChartView(Context ctx){super(ctx);}
//========================
@Override
public void onSizeChanged(int nw, int nh, int ow, int oh){
super.onSizeChanged(nw, nh, ow, oh);
d = nw>nh?nh:nw;
rec = new RectF(0, 0, d, d);
p.setFlags(Paint.ANTI_ALIAS_FLAG);
}
//========================
public void setTextSize(float size){textSize=size;}
//========================
/**Set data to be shown in pie chart view
* @param dList ArrayList of Object[], 1st element will contain the name, 2nd the percentage (int)
*/
public void setData(ArrayList<Object[]> dList){
data = new String[dList.size()][2];
int i=0;
for(Object[] op:dList){
data[i++] = new String[]{op[0]+"",op[1]+""};
}
}
}