I am implementing achartengine within a ViewPager. The view holding the chart has a spinner with 7 options where you can choose which data you want to view. 6 of the options return a PieChartView and the last one returns a TimeChartView.
The PieChartView charts update and redraw as expected, but when selecting the TimeChartView option, nothing happens. The view stays with the previously selected PieChartView and doesn't throw an error. I've implemented TimeChartView successfully elsewhere in the app and comparisons of the code and the data feeding the chart haven't thrown up any flags, so I can only assume that my method of switching graph types is incorrect.
The code extract below is the part which deals with switching the views; any advice would be appreciated.
try{
//if mChartView is already created (has data)
//we need to invalidate it because it will only accept
//data less than or equal to the length of data it currently has
if(mChartView != null){
mChartView.invalidate();
}
if(graphType >= 6){
mChartView = ChartFactory.getTimeChartView(ctx, mDataset, genericXYRenderer, "MM/dd");
genericXYRenderer.setClickEnabled(false);
}else{
mChartView = ChartFactory.getPieChartView(ctx, genericSeries, genericRenderer);
genericRenderer.setClickEnabled(false);
genericRenderer.setSelectableBuffer(10);
}
layout.addView(mChartView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mChartView.repaint();
} catch (Exception e) {
Log.e("[appname]", "Error trying to set ChartView", e);
m_Logger = new Logger();
m_Logger.error(e);
}
Many Thanks, Dave