2013-07-09 26 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());