2016-07-01 3 views
3

내 앱에서 Mp piechart를 사용 중입니다. 매우 작은 크기를 보여 주지만 크기를 늘리려고하지만 크기가 커지는 것은 아닙니다. 나는 문제를 발견 할 수 없다. 가능한 크기를 알려주십시오.Mp piechart 크기 증가

public class MPpiechart extends Activity { 

private LinearLayout mainLayout; 
private PieChart mChart; 
// we're going to display pie chart for smartphones martket shares 
private float[] yData = { 5, 10, 15, 30, 40 }; 
private String[] xData = { "Sony", "Huawei", "LG", "Apple", "Samsung" }; 

@Override 
protected 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; 
} 

@Override 
protected 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, segStartPoint, segment[i], 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> 

답변

1

파이 데이터 크기 내부

.setValueTextSize(12); 

센터 데이터 크기

.setCenterTextSize(30);