【问题标题】:Making Concentric Pie Chart in Android在Android中制作同心饼图
【发布时间】:2013-12-13 06:21:52
【问题描述】:

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

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

感谢提前帮助 :)

【问题讨论】:

  • 所以你想制作甜甜圈图..不是饼图..对吗??
  • 哦,是的..这是甜甜圈图,是的,我想要这个..我之前做过的事情,因为我遇到了一个与这个..tht war ur's 相关的线程......所以有你实现了??
  • 是的..检查答案..

标签: android graph android-canvas achartengine android-graphview


【解决方案1】:

这里是示例,首先在您的view(xml) 中创建一个LinearLayout 并在您的activity 中获取它以传递它SingleDonutGraph 类以在此布局上绘制donut graph。您还必须传递@ 987654326@as double array(你必须在甜甜圈图上设置的值)。

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

【讨论】:

  • 如何在其上添加文本以及如何提供一个小的圆形边距 b/w 中心圆圈和外部图表
  • 要在其上添加文本,您应该切换到 RelativyLayout 而不是 LinearLayout..尝试使用 RealativeLayout CenterInParent align 属性..
  • 还有一件事 Abhijit 如何在空心黑色圆圈之后放置边距环
【解决方案2】:

试试this

也许它会帮助你 .谢谢!

【讨论】:

    【解决方案3】:

    这两行有所不同:

    mChartView2 = ChartFactory.getDoughnutChartView(context, categorySeries,渲染器);

    parent.addView(mChartView2);
    
    return ChartFactory.getDoughnutChartIntent(context, categorySeries,
            renderer, null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-22
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      相关资源
      最近更新 更多