饼图:如何使用AChartEngine Android库在某些饼图上显示文本?

时间:2022-12-03 17:43:02

I'm using AChartEngine (http://code.google.com/p/achartengine/) library to display a pie chart in an Android app.

我正在使用AChartEngine(http://code.google.com/p/achartengine/)库在Android应用中显示饼图。

The pie chart can have lots of slides. I want to display just on some pie slices the values, but I could not make it work (I'm not even sure it is possible).

饼图可以有很多幻灯片。我想在一些饼上显示值,但我无法使它工作(我甚至不确定它是否可行)。

For the DefaultRenderer I've made:

对于我做过的DefaultRenderer:

renderer.setLabelsColor(Color.BLACK);  // color of the text displayed on the chart
renderer.setLabelsTextSize(12); // size of the text displayed on the chart

and for each SimpleSeriesRenderer:

并为每个SimpleSeriesRenderer:

if (pieSlidesNo > 5) {
    serieRender.setDisplayChartValues(false);
} else {
    serieRender.setDisplayChartValues(true);
}

but is not working - the values are displayed on each pie slice. What I want is like in the below image (the values are displayed only on first slices, not on all).

但不起作用 - 值显示在每个饼图上。我想要的就像在下面的图像(值只显示在第一个切片上,而不是全部显示)。

饼图:如何使用AChartEngine Android库在某些饼图上显示文本?

1 个解决方案

#1


2  

For this you have to change Library Source.

为此,您必须更改库源。

Make change in draw() of PieChart.java and use renderer.setDisplayValues(true); of DefaultRenderer

在PieChart.java的draw()中进行更改并使用renderer.setDisplayValues(true); DefaultRenderer

 if (mRenderer.isDisplayValues()) {
        if(angle<60)
        {}
        else
        drawLabel(
            canvas,
            getLabel(mRenderer.getSeriesRendererAt(i).getChartValuesFormat(), mDataset.getValue(i)),
            mRenderer, prevLabelsBounds, mCenterX, mCenterY, shortRadius / 2, longRadius / 2,
            currentAngle, angle, left, right, mRenderer.getLabelsColor(), paint, false, true);
      }

you can change angle comparison value (angle<60) according to ur requirement.

你可以根据你的要求改变角度比较值(角度<60)。

#1


2  

For this you have to change Library Source.

为此,您必须更改库源。

Make change in draw() of PieChart.java and use renderer.setDisplayValues(true); of DefaultRenderer

在PieChart.java的draw()中进行更改并使用renderer.setDisplayValues(true); DefaultRenderer

 if (mRenderer.isDisplayValues()) {
        if(angle<60)
        {}
        else
        drawLabel(
            canvas,
            getLabel(mRenderer.getSeriesRendererAt(i).getChartValuesFormat(), mDataset.getValue(i)),
            mRenderer, prevLabelsBounds, mCenterX, mCenterY, shortRadius / 2, longRadius / 2,
            currentAngle, angle, left, right, mRenderer.getLabelsColor(), paint, false, true);
      }

you can change angle comparison value (angle<60) according to ur requirement.

你可以根据你的要求改变角度比较值(角度<60)。