如何在Android中从aChartEngine定制甜甜圈图表?

如何在Android中从aChartEngine定制甜甜圈图表?,android,achartengine,pie-chart,donut-chart,Android,Achartengine,Pie Chart,Donut Chart,我正在使用aChartEngine库在我的android应用程序中创建甜甜圈图,但我无法将背景图像设置为甜甜圈图。。 1如何为圆环图设置边框颜色 2如何在甜甜圈中心添加标签 3以及如何将自定义图像设置为甜甜圈作为背景 我的甜甜圈活动是 public class DonutGraph { private GraphicalView mChartView2; static int count = 2; int[] Mycolors = new int[] { Color.parseColor("#

我正在使用aChartEngine库在我的android应用程序中创建甜甜圈图,但我无法将背景图像设置为甜甜圈图。。 1如何为圆环图设置边框颜色 2如何在甜甜圈中心添加标签 3以及如何将自定义图像设置为甜甜圈作为背景

我的甜甜圈活动是

public class DonutGraph {
private GraphicalView mChartView2;
static int count = 2;

int[] Mycolors = new int[] { Color.parseColor("#FF0000"),Color.parseColor("#000000") };
String[] labels = { "HEADTRAUMA" , "TOTAL"};


public Intent execute(Context context, LinearLayout parent,double values[]) {
    parent.removeAllViews();
    int[] colors = new int[count];
    for (int i = 0; i < count; i++) {
        colors[i] = Mycolors[i];
    }
    DefaultRenderer renderer = buildCategoryRenderer(colors);
    renderer.setShowLabels(true);
    renderer.setInScroll(true);
    renderer.setStartAngle(90);
    renderer.setPanEnabled(false);// Disable User Interaction
    renderer.setScale((float) 1.4);
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.BLACK);

    MultipleCategorySeries categorySeries = new MultipleCategorySeries(
            "HEADTRAUMA");
    categorySeries.add(labels, values);

    mChartView2 = ChartFactory.getDoughnutChartView(context,
            categorySeries, renderer);

    parent.addView(mChartView2);

    return ChartFactory.getDoughnutChartIntent(context, categorySeries,
            renderer, null);
}

protected DefaultRenderer buildCategoryRenderer(int[] colors) {
    DefaultRenderer renderer = new DefaultRenderer();
    for (int color : colors) {
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(color);
        renderer.addSeriesRenderer(r);

    }
    return renderer;
}
}

提前感谢。

对于标签和背景,您可以使用覆盖,使用另一个视图,一个在下面的视图作为背景,另一个在上面的视图作为标签,所有这些都比在具有相同度量的同一视图组中更容易,我想

但是对于边框,您需要在char引擎源代码的类DoughnutChart上进行更改,更具体地说是在方法draw上

我不进行测试,但这可能会解决您的问题:

paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(strokeWidth);
paint.setStrokeCap(Paint.Cap.SQUARE);
在这一行之后:

paint.setColor(mRenderer.getSeriesRendererAt(i).getColor());

你们解决问题了吗?是的,解决了…请检查