我正在尝试为添加到我的应用中的每个用户创建一个图表。此图表将以x轴显示此格式21 Dec 2012
的日期和30至30000的数字。假设这是第1天,用户添加每小时卡路里燃烧率,我希望将此信息放入图表中。第二天,我希望他们能够计算出他们每小时的卡路里率并将其存储到图表中。有点像将其附加到图表中。
公共类图扩展了Activity {
private XYMultipleSeriesDataset mDataset;
private XYMultipleSeriesRenderer mRenderer;
List<double[]> values = new ArrayList<double[]>();
private GraphicalView mChartView;
private TimeSeries time_series;
String gotCal;
Double[] thisDou;
Double convert;
Date date;
// chart container
private LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layout = (LinearLayout) findViewById(R.id.chart);
SharedPreferences calStuff = getSharedPreferences("Calories", 0);
if (calStuff != null) {
gotCal = calStuff.getString("This Cal", null);
System.out.println(gotCal);
}
convert = Double.parseDouble(gotCal);
// create dataset and renderer
mDataset = new XYMultipleSeriesDataset();
mRenderer = new XYMultipleSeriesRenderer();
//mRenderer.setAxisTitleTextSize(16);
//mRenderer.setChartTitleTextSize(20);
//mRenderer.setLabelsTextSize(15);
//mRenderer.setLegendTextSize(15);
//mRenderer.setPointSize(3f);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.GREEN);
r.setFillPoints(true);
r.setPointStyle(PointStyle.DIAMOND);
//r.fillPoints(true);
r.setFillBelowLine(true);
mRenderer.addSeriesRenderer(r);
mRenderer.setZoomButtonsVisible(true);
mRenderer.setXTitle("Date");
mRenderer.setYTitle("Calories Burned Per Hour");
//mRenderer.setClickEnabled(true);
r.setDisplayChartValues(true);
mRenderer.setSelectableBuffer(20);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.BLACK);
mRenderer.setGridColor(Color.CYAN);
//mRenderer.setChartTitle("LOOOOOL");
//mRenderer.setYLabels(12);
mRenderer.setPanEnabled(true, true);
//mRenderer.setPanEnabled(true);
time_series = new TimeSeries("test");
mDataset.addSeries(time_series);
fillData();
//time_series.add(date, Double.parseDouble(gotCal));
mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
"dd MMM yyyy");
if (mChartView == null)
mChartView.repaint();
layout.addView(mChartView);
}
private void fillData() {
long value = new Date().getTime() - 3 * TimeChart.DAY;
for (int i = 0; i < gotCal.length(); i += convert) {
//date = new Date(value + i * TimeChart.DAY / 31);
time_series.add(new Date(value + i * TimeChart.DAY / 20), i);
}
}
它只适用于一个用户,因此当我尝试从具有不同信息的其他用户访问图表时,没有图表,为什么会这样?另外,如何将图表专门保存给该用户?非常感谢任何帮助,谢谢。