这是我的代码:
public class MPpIEchart extends Activity {private linearLayout mainLayout;private PIEChart mChart;// we're going to display pIE chart for smartphones martket sharesprivate float[] yData = { 5,10,15,30,40 };private String[] xData = { "Sony","Huawei","LG","Apple","Samsung" };@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.pIEgraph); mainLayout = (linearLayout) findVIEwByID(R.ID.mainLayout); mChart = new PIEChart(this); // add pIE chart to main layout mainLayout.addVIEw(mChart); mainLayout.setBackgroundcolor(color.parsecolor("#55656C")); // configure pIE chart mChart.setUsePercentValues(true); mChart.setDescription("Smartphones Market Share"); // enable hole and configure mChart.setDrawHoleEnabled(true); //mChart.setHolecolortransparent(true); mChart.setHoleRadius(7); mChart.settransparentCircleRadius(10); // enable rotation of the chart by touch mChart.setRotationAngle(0); mChart.setRotationEnabled(true); // set a chart value selected Listener mChart.setonChartValueSelectedListener(new OnChartValueSelectedListener() { @OverrIDe public voID onValueSelected(Entry e,int dataSetIndex,Highlight h) { // display msg when value selected if (e == null) return; Toast.makeText(MPpIEchart.this,xData[e.getXIndex()] + " = " + e.getVal() + "%",Toast.LENGTH_SHORT).show(); } @OverrIDe public voID onnothingSelected() { } }); // add data addData(); // customize legends Legend l = mChart.getLegend(); l.setposition(Legend.Legendposition.RIGHT_OF_CHART); l.setXEntrySpace(7); l.setYEntrySpace(5);}private voID addData() { ArrayList<Entry> yVals1 = new ArrayList<Entry>(); for (int i = 0; i < yData.length; i++) yVals1.add(new Entry(yData[i],i)); ArrayList<String> xVals = new ArrayList<String>(); for (int i = 0; i < xData.length; i++) xVals.add(xData[i]); // create pIE data set PIEDataSet dataSet = new PIEDataSet(yVals1,"Market Share"); dataSet.setSliceSpace(3); dataSet.setSelectionShift(5); // add many 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()); dataSet.setcolors(colors); // instantiate pIE data object Now PIEData data = new PIEData(xVals,dataSet); data.setValueFormatter(new PercentFormatter()); data.setValueTextSize(11f); data.setValueTextcolor(color.GRAY); mChart.setData(data); // undo all highlights mChart.highlightValues(null); // update pIE chart mChart.invalIDate();}
PIEgraph.java
public class PIEGraph extends VIEw {private Paint pIEPaint;private RectF rectF;private float[] data;public PIEGraph(Context context,AttributeSet attrs){ super(context,attrs); pIEPaint = new Paint(); pIEPaint.setAntiAlias(true); pIEPaint.setDither(true); pIEPaint.setStyle(Paint.Style.FILL); /* mShadowPaint = new Paint(0); mShadowPaint.setcolor(0xff101010); mShadowPaint.setMaskFilter(new BlurMaskFilter(8,BlurMaskFilter.Blur.norMAL));*/}public float[] pIESegment(){ float[] segValues = new float[this.data.length]; float Total = getTotal(); for (int i = 0; i < this.data.length; i++){ segValues[i] = (this.data[i]/Total) * 360; } // x = ( radius of pIE chart /2)*cos(angle in radians) [angle in radians = Math.toradians(half the sweep angle in degrees) return segValues;}public float getTotal(){ float total = 0; for (float val : this.data){ total +=val; } return total;}@OverrIDeprotected voID onDraw(Canvas canvas){ if (data != null){ int top = 0; int left = 0; int endBottom = getHeight(); int endRight = endBottom; rectF = new RectF(left,top,endRight,endBottom); float[] segment = pIESegment(); float segStartPoint = 0; for (int i = 0; i < segment.length; i++){ Random rnd = new Random(); int[] color = {getResources().getcolor(R.color.blue),getResources().getcolor(R.color.yellow),getResources().getcolor(R.color.red),getResources().getcolor(R.color.gray)}; // int color = color.argb(255,(int)segment[i],rnd.nextInt(256),rnd.nextInt(256)); String[] name ={(String) getResources().getText(R.string.Energy),(String) getResources().getText(R.string.Fat),(String) getResources().getText(R.string.Fiber),(String) getResources().getText(R.string.Methi)}; pIEPaint.setcolor(color[i]); canvas.drawText(name[i],segStartPoint,segment[i],pIEPaint); canvas.drawArc(rectF,true,pIEPaint); segStartPoint += segment[i]; } }}public voID setData(float[] data){ this.data = data; invalIDate();}}
pIEgraph.xml:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <relativeLayout androID:gravity="center" androID:orIEntation="vertical" androID:ID="@+ID/mainLayout" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > </relativeLayout></linearLayout>解决方法 内部饼图数据大小
.setValueTextSize(12);
中心数据大小
.setCenterTextSize(30);总结
以上是内存溢出为你收集整理的android – Mp饼图大小增加全部内容,希望文章能够帮你解决android – Mp饼图大小增加所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)