使用AChartEngine库图,没能得到价值不同势X轴值 [英] Using AChartEngine library for graphs, not able to get value for diffrent x-axis value

查看:106
本文介绍了使用AChartEngine库图,没能得到价值不同势X轴值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static ArrayList<double[]> Value = new ArrayList<double[]>();
    private double[] x = new double[10];
    private double[] y = new double[10];
    int counter = -1;

add.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                counter++;
                x[counter] = Double.parseDouble(income_1.getText().toString());
                y[counter] = Double.parseDouble(income_2.getText().toString());
                income_1.setText("");
                income_2.setText("");
            }
        });

publish.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Value != null) {
                    Value.add(x);
                    Value.add(y);
                    Intent intent = salesStackedBarChart.execute(BarChart.this,
                            Value, counter);
                    startActivity(intent);
                }
            }
        });


//and in SalesStackedBarChart.java class

public Intent execute(Context context, ArrayList<double[]> values ,int counter) {
        int count = counter + 1;
        double fcount = counter + 1.5;
        String[] titles = new String[] { "Android", "iPhone" };
        int[] colors = new int[] { Color.GREEN, Color.CYAN };
        XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
        setChartSettings(renderer, "Yearly revenue in the last "+count+" years", "Years", "revenue in $", 0.5,
                fcount, 0, 24000, Color.GRAY, Color.LTGRAY);
        renderer.setXLabels(count);
        renderer.setYLabels(10);
        renderer.setDisplayChartValues(true);
        renderer.setXLabelsAlign(Align.LEFT);
        renderer.setYLabelsAlign(Align.LEFT);
        renderer.setZoomRate(1.1f);
        renderer.setBarSpacing(0.5);
        return ChartFactory.getBarChartIntent(context, buildBarDataset(titles, values), renderer,
            Type.DEFAULT);
      }

// in AbstractDemoChart.java class

 protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values) {
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    int length = titles.length;
    for (int i = 0; i < length; i++) {
      CategorySeries series = new CategorySeries(titles[i]);
      double[] v = values.get(i);
      int seriesLength = v.length;
      for (int k = 0; k < seriesLength; k++) {
        series.add(v[k]);
      }
      dataset.addSeries(series.toXYSeries());
    }
    return dataset;
  }

运行这个项目我得到与x轴值图:

Run this project i get graph with x- axis value:

1,2,3,4,5....

但我想打印值:

2005,2006,2007,2008.....

我在一些code变了样:

I changed in some code like:

setChartSettings(renderer, "Yearly revenue in the last "+count+" years", "Years", "revenue in $", 2005,
                2010, 0, 24000, Color.GRAY, Color.LTGRAY);

和运行项目中,我得到这样的x轴的值:

and run project i get value of x-axis like:

2005,2006,2007....

但得不到图巴的价值。所有的x轴的值都为空。我怎样才能使这项工作?
    

but not get graph bar value. Values of all x-axis are null. How can I make this work?

推荐答案

公共静态的ArrayList&LT;双层[]&GT;值=新的ArrayList&LT;双层[]&GT;(); 结果
 私人双重[] X =新的双[2010]; 结果
私人双重[] Y =新的双[2010]; 结果
  INT计数器= 2005;

这篇关于使用AChartEngine库图,没能得到价值不同势X轴值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆