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轴值的图表:
1,2,3,4,5....
但我想打印价值:
2005,2006,2007,2008.....
我更改了一些代码:
setChartSettings(renderer, "Yearly revenue in the last "+count+" years", "Years", "revenue in $", 2005,
2010, 0, 24000, Color.GRAY, Color.LTGRAY);
并运行项目我获得x轴的值,如:
2005,2006,2007....
但没有得到图形条值。所有x轴的值均为空。我怎样才能做到这一点?
答案 0 :(得分:2)
public static ArrayList<double[]> Value = new ArrayList<double[]>();
private double[] x = new double[2010];
private double[] y = new double[2010];
int counter = 2005;
答案 1 :(得分:0)
我这样做了:
xScale = 5;
Calendar today = Calendar.getInstance();
for (int i = 0; i < this.xScale; i++) {
Calendar c = (Calendar) today.clone();
c.set(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DATE) - (this.xScale - (i + 1)));
x.get(0)[i] = new Date(c.get(Calendar.YEAR) - 1900, c.get(Calendar.MONTH), c.get(Calendar.DATE));
x.get(1)[i] = new Date(c.get(Calendar.YEAR) - 1900, c.get(Calendar.MONTH), c.get(Calendar.DATE));
}
这显示了x轴的最后5天