gpt4 book ai didi

android - Mp 饼图大小增加

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:49 34 4
gpt4 key购买 nike

我在我的应用程序中使用 Mp 饼图。它显示非常小的尺寸,我试图增加它的尺寸但它没有增加它的尺寸。我无法找出问题所在。请告诉我们如何增加尺寸。

这是我的代码:

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>

最佳答案

内部饼图数据大小

.setValueTextSize(12);

对于中心数据大小

.setCenterTextSize(30);

关于android - Mp 饼图大小增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38147607/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com