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;
}
Run this project i get graph with x- axis value:
1,2,3,4,5....
But I want to print value:
2005,2006,2007,2008.....
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);
and run project i get value of x-axis like:
2005,2006,2007....
but not get graph bar value. Values of all x-axis are null. How can I make this work?