achartengine:为CategorySeries神秘添加值

时间:2013-09-19 12:46:28

标签: java android charts achartengine

你能建议一下吗?

问题:

我正在使用achartengine库(achartengine)在我的Android应用程序中绘制饼图:

问题 - 它适用于模拟器,但不适用于真正的手机 正如我发现的那样(真正的手机)认为价值都是零 我在添加到系列之前记录了应用程序中的值,之后在系列元素之后记录了它们 - 它们不是零 我已经完成了应该做的一切 - 导出的库achartengine-1.1.0.jar等等,除此之外它还可以正常工作

细节:

我将Integer arrayList传递给我的类(这将是饼图的数据) 然后我将它转换为double,因为add方法接受双值:

Add

add

public void add(java.lang.String category,
            double value)
Adds a new value to the series.
Parameters:
category - the category
value - the new value  

这是我绘制饼图的课程

public class piegraph {

public Intent getIntent(Context context, ArrayList<Integer> arraylist) {

    double val1 = arraylist.get(0).doubleValue();
    double val2 = arraylist.get(1).doubleValue();
    double val3 = arraylist.get(2).doubleValue();
    double val4 = arraylist.get(3).doubleValue();
    double val5 = arraylist.get(4).doubleValue();
    double val6 = arraylist.get(5).doubleValue();


    CategorySeries series = new CategorySeries("Pie iGraph");


    // the way it doesn't work on a phone:

    series.add("6A", val1);
    series.add("6B", val2);
    series.add("6C", val3);
    series.add("7A", val4);
    series.add("7B", val5);
    series.add("7C", val6);


    // the way it works on a phone:

 /*
    series.add("6A", 2);
    series.add("6B", 3);
    series.add("6C", 4);
    series.add("7A", 6);
    series.add("7B", 3);
    series.add("7C", 3); */

    int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN, Color.LTGRAY };

    DefaultRenderer renderer = new DefaultRenderer();
    for (int color : colors) {
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(color);
        renderer.addSeriesRenderer(r);
    }
    renderer.setChartTitle("This month");
    renderer.setChartTitleTextSize(7);
    renderer.setZoomButtonsVisible(true);

    Intent intent = ChartFactory.getPieChartIntent(context, series, renderer, "Pie");
    return intent;
    }
}  

我调用它并像这样传递数组列表:

public void onClick(View v) {

    switch (v.getId()) {
    case R.id.btnGra:

    ArrayList<Integer> arra = new ArrayList<Integer>();

        arra.add(sum_6a);
        arra.add(sum_6b);
        arra.add(sum_6c);
        arra.add(sum_7a);
        arra.add(sum_7b);
        arra.add(sum_7c);


    piegraph pie = new piegraph();
    Intent lineIntent = pie.getIntent(this, arra);
    startActivity(lineIntent);

    break;

    }
}  

所以我真的不知道可能出现什么问题,在两部手机上测试过,Android 2.3.6,目标版本是2.3.3

谢谢!

0 个答案:

没有答案