1

achartengine用来绘制图表,当新值插入数据库时​​会更新。

chart()
{
 if (mChartView == null) 
 {          
  d = new BuildMultipleDataset();           
  db.open();

  //code for some database query            
  LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
  mChartView = ChartFactory.getLineChartView(this, d.datasetbuilder(cursor1,cursor2), d.render());
  layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, chartHeight));      

  db.close();       
 }
 else 
 {
  mChartView.repaint();
 }
}

当从数据库触发更新时,我调用此方法。那时我让 mChartView = null; 但问题是它没有绘制更新的图表。仅当我切换屏幕方向时,更新才会反映到图表中。我的代码有什么问题?

4

1 回答 1

2

mChartView = null;只有当我删除视图、设置、定义mChartView和设置视图时,我才能让它工作。

IE

layout.removeView(mChartView);
mChartView = null;
mChartView = ChartFactory //rest of mChartView code
layout.addView(mChartView);
于 2011-08-15T14:58:27.133 回答