我正在尝试为添加到我的应用程序中的每个用户创建一个图表。此图表将在21 Dec 2012
x 轴上以这种格式显示日期和从 30 到 30000 的数字。假设这是第 1 天,用户添加他们每小时的卡路里燃烧率,我希望将该信息放入图表中。第二天,我希望他们能够计算他们每小时的卡路里消耗率并将其存储到图表中。有点像将其附加到图表中。公共类图扩展活动{
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);
}
}
它仅适用于一个用户,所以当我尝试从具有不同信息的不同用户访问图表时,没有图表,这是为什么呢?另外,如何将图表专门保存给该用户?任何帮助都非常感谢,谢谢。