mpandroidchart für mein Projekt, ich möchte das Ergebnis genau wie das Bild unten.Ich habe einige Fragen haben lange Zeit. Die erste möchte ich die Daten zeigen ist 11,23%, aber das Projekt 11,2% für mich zeigen, kann ich keine Möglichkeit finden, es zu ändern, bitte helfen Sie mir. Die zweite möchte ich die Legende ist wie das Bild unten, aber die legent of mpandroidchart-barchar keine Beschreibung, wie kann ich tun? Die dritte Frage ist, dass ich die y-Achse wie das untere Bild ändern möchte, ich weiß nicht, ob es realisiert wird? !MPAndroidChart-BarChart, das folgende ist detaillierte Beschreibung
[Ich möchte Bild]: http://i.stack.imgur.com/tuXhb.png
[Mein Bild jetzt]: http://i.stack.imgur.com/NG9FB.png public class BarChartActivity erstreckt Aktivität {
private BarChart barChart;
private BarData data;
private BarDataSet dataSet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bar_chart);
barChart = (BarChart) findViewById(R.id.barchart);
barChart.getAxisRight().setEnabled(false); // 隐藏右边的y轴
barChart.getXAxis().setPosition(XAxisPosition.BOTTOM);
barChart.setGridBackgroundColor(Color.WHITE); // 设置背景色
barChart.getXAxis().setDrawGridLines(false); // 隐藏网格竖线
YAxis yAxis = barChart.getAxisLeft(); // 得到y轴坐标
yAxis.setStartAtZero(false); // y轴是否从0开始
yAxis.mAxisMinimum = -20f;
yAxis.setLabelCount(10); // x轴横线的条数
yAxis.setAxisMinValue(-100f); // 设置最小值
yAxis.setAxisMaxValue(99f);
// yAxis.setSpaceTop(100);
// yAxis.setSpaceBottom(-100);
// barChart.setVisibleYRange(50f,null);
// barChart.getXAxis().enableGridDashedLine(400, 50, 0);
// barChart.getAxisLeft().resetAxisMaxValue(); //自动调整y轴的最大值
// legend.setLabels(new String[]{"你好","我好","大家好"});
barChart.getLegendRenderer();
barChart.getXAxis().setAxisLineColor(Color.BLUE); // 设置x轴线的颜色
barChart.getAxisLeft().setAxisLineColor(Color.GREEN); // 设置y轴线的颜色
barChart.getAxisLeft().setGridColor(Color.RED); // x轴线的颜色
barChart.getAxisLeft().setGridLineWidth(1f); // x轴网格线的宽度
barChart.getAxisLeft().setSpaceTop(150f);
barChart.getAxisLeft().setTextColor(Color.RED);// y坐标轴的上的刻度文字的颜色
// List<String> list = new ArrayList<String>();
// list.add("你好");
// list.add("你好1");
// list.add("你好2");
// barChart.getLegend().setLabels(list);
Legend legend = barChart.getLegend();
legend.setXEntrySpace(5f);
legend.setYEntrySpace(20f);
barChart.getXAxis().setSpaceBetweenLabels(5);
barChart.getXAxis().setYOffset(2f);
barChart.getAxisLeft().setValueFormatter(new PercentFormatter());
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();// 显示的条目
ArrayList<String> xVals = new ArrayList<String>(); // 横坐标标签
float[] yValues = getYValues(90.23f, -2.84f, 9.21f);
for (int i = 0; i < 3; i++) {
entries.add(new BarEntry(yValues[i], i));
xVals.add(""); // 可以从这里取消x轴的坐标
}
int[] colors = new int[] { Color.rgb(90, 147, 229),
Color.rgb(247, 183, 48), Color.rgb(245, 70, 70) };
dataSet = new BarDataSet(entries, ""); // 原来是公司你利润报表
dataSet.setColors(colors);
dataSet.setBarSpacePercent(70f); // 设置柱子的宽度
dataSet.setValueFormatter(new PercentFormatter()); // 设置柱子上的数字百分数显示
dataSet.setValueTextColor(Color.BLUE); // 柱子上数字的颜色
data = new BarData(xVals, dataSet);
barChart.setData(data);
barChart.animateY(3000);
barChart.setDescription("");// 公司前半年财务报表(单位:万元)
barChart.getLegend().setPosition(LegendPosition.BELOW_CHART_CENTER); // 设置图例在正下方
barChart.getLegend().setStackSpace(50f); // 设置图例之间的距离
dataSet.setValueTextSize(28); // 设置柱子上数字的大小
}
public float[] getYValues(float x, float y, float z) {
return new float[] { x, y, z };
}
}
Wo ist das Bild? Veröffentlichen Sie Ihren Code auch –
Ich Englisch ist nicht gut, ich habe mein Bild, und der Code bitte warten Sie einen Moment, –