2

今天我在以语法方式在 Android Pro 中绘制图形时遇到了一个问题。我正在使用 Achartengine 图形库来实现这一点,我已经完成了简单的饼图,但我不知道如何使用它制作同心饼图。

这是我想要制作的图形演示图像。

提前感谢您的帮助:)在此处输入图像描述

4

3 回答 3

3

这是示例,首先在您的文件中创建一个并LinearLayout在您的文件中将其传递给该类以在此布局上绘制一个。您还必须作为双数组传递(您必须在圆环图上设置的值)。view(xml)activitySingleDonutGraphdonut graphgraphValues[]

LayoutToDisplayChartLeftGraph = (LinearLayout) findViewById(R.id.right_graph_for_punch_count);
Intent achartIntentLeft = new SingleDonutGraph().execute(TabletPunchCountActivity.this, LayoutToDisplayChartLeftGraph,graphValues);

然后使用这个类SingleDonutGraph.java

public class SingleDonutGraph {
private GraphicalView mChartView2;
static int count = 3;

int[] Mycolors = new int[] { Color.parseColor("#F2846B"),
        Color.parseColor("#A01115"), Color.parseColor("#741E1E") };
String[] labels = { "TODAY", "AVERAGE", "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(false);
    renderer.setBackgroundColor(Color.BLACK);
    renderer.setPanEnabled(false);// Disable User Interaction
    renderer.setScale((float) 1.4);
    renderer.setInScroll(true); //To avoid scroll Shrink        
    renderer.setStartAngle(90);
    renderer.setShowLegend(false);


    MultipleCategorySeries categorySeries = new MultipleCategorySeries(
            "Punch Graph");
    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;
}
}
于 2013-12-13T06:39:40.477 回答
1

试试这个

可能它会帮助你。谢谢!

于 2013-12-13T06:29:36.567 回答
0

这两行有所不同:

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

parent.addView(mChartView2);

return ChartFactory.getDoughnutChartIntent(context, categorySeries,
        renderer, null);
于 2013-12-19T12:30:02.993 回答