问题
I'm using AChartEngine to create Pie Chart on Android .It's OK. But I want to remove "Line connect to Label from Pie ".
This is my code:
// Instantiating a renderer for the Pie Chart
DefaultRenderer defaultRenderer = new DefaultRenderer();
for(int i = 0 ;i<distribution.length;i++){
SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
seriesRenderer.setColor(colors[i]);
seriesRenderer.setDisplayChartValues(true);
seriesRenderer.setDisplayChartValuesDistance(0);
seriesRenderer.setShowLegendItem(false);
// Adding a renderer for a slice
defaultRenderer.addSeriesRenderer(seriesRenderer);
}
defaultRenderer.setZoomButtonsVisible(false);
defaultRenderer.setClickEnabled(false);
defaultRenderer.setPanEnabled(true);
defaultRenderer.setAntialiasing(true);
defaultRenderer.setShowLabels(true);
defaultRenderer.setShowLegend(false);
// Creating an intent to plot bar chart using dataset and multipleRenderer
Intent intent = ChartFactory.getPieChartIntent(getBaseContext(), distributionSeries , defaultRenderer, "AChartEnginePieChartDemo");
// Start Activity
startActivity(intent);
Please see image to know clearly:
Now : http://i.stack.imgur.com/JwM1B.png
I want: http://i.stack.imgur.com/olWB2.png
Please help me !
Thanks!
回答1:
Try this..
If you want to remove only the labels:
defaultRenderer.setShowLabels(false);
If you want to remove only the legend:
defaultRenderer.setShowLegend(false);
回答2:
If you want to remove only the labels: renderer.setShowLabels(false);
If you want to remove only the legend: renderer.setShowLegend(false);
回答3:
final CategorySeries series = new CategorySeries("pie");
for (int i = 0; i < Xaxes_value.size(); i++) {
series.add(Xaxes_value.get(i) + "",
Long.parseLong(yaxes_value.get(i)));
}
List<Integer> colors = new ArrayList<Integer>();
int[] colorr = { Color.parseColor("#56ADDB"),
Color.parseColor("#F59331"), Color.parseColor("#73C83C"),
Color.parseColor("#948D8B"), Color.parseColor("#E54273"),
Color.parseColor("#FFD34E"), Color.parseColor("#2A86D6"),
Color.parseColor("#00BFC0"), Color.parseColor("#95AC5F"),
Color.parseColor("#FF8497") };
for (int i = 0; i < yaxes_value.size(); i++) {
colors.add(colorr[i]);
}
renderer = new DefaultRenderer();
for (int color = 0; color < colors.size(); color++) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors.get(color));
r.setDisplayBoundingPoints(false);
// r.setDisplayChartValuesDistance(20);
r.setDisplayChartValues(false);
r.setChartValuesTextSize(18);
r.setStroke(BasicStroke.SOLID);
renderer.addSeriesRenderer(r);
}
// renderer.isInScroll();
renderer.setZoomEnabled(false);
renderer.setPanEnabled(false);
renderer.setZoomButtonsVisible(false); // set zoom button in Graph
renderer.setApplyBackgroundColor(false);
renderer.setBackgroundColor(Color.WHITE); // set background color
renderer.setChartTitle("Pie Chart");
renderer.setLabelsColor(Color.BLACK);
renderer.setMargins(new int[] { 20, 100, 20, 15 });
renderer.setLabelsTextSize(20);
renderer.setChartTitleTextSize((float) 30);
renderer.setShowLabels(false);
renderer.setLegendTextSize(25);
renderer.setDisplayValues(true);
renderer.setStartAngle(90);
GraphicalView mChart = ChartFactory.getPieChartView(getApplicationContext(), series,
renderer);
layout_graph.addView(mChart);
来源:https://stackoverflow.com/questions/19266543/android-piechart-using-achartengine