2013-07-09 45 views
1

我正在使用aChartEngine库在我的android应用程序中创建甜甜圈图表,但我无法将背景图像设置为我的甜甜圈图形。我有一些问题以下。 1)如何将边框颜色设置为甜甜圈图形 2 )如何在甜甜圈 3)以及如何设置自定义图像甜甜圈作为背景的中心添加一个标签如何在Android中从aChartEngine制作自定义的甜甜圈图表?

我的甜甜圈活动事先

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; 
} 
} 

感谢。

+0

你解决问题? –

+0

已解决...请检查http://stackoverflow.com/questions/17917972/how-to-set-image-inside-of-donut-achartengine-graph –

回答

0

对于标签和背景,你可以使用覆盖,使用其他视图之一下面为背景,另一个在顶部的标签,所有比具有相同指标相同的ViewGroup里,很容易我猜。

但对于边界,您将需要更改类DoughnutChart在焦炭引擎源代码,更具体的方法平局。

我不考,但也许这应该解决您的问题:这一行后

paint.setStyle(Paint.Style.STROKE); 
paint.setStrokeWidth(strokeWidth); 
paint.setStrokeCap(Paint.Cap.SQUARE); 

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