I have a layout with a button. When I press the button, a custom dialog appears with a pie chart. For simplicity, I am using static values. I press the back button to cancel the dialog, then press the button again to show the dialog with the pie chart, but the chart is missing, all I have is a blank dialog. What can be the reason?
Btw, I have another button in that layout to show another chart. No matter which chart I show first, the other does not appear after that.
I have to reload the activity (layout) to be able to show the chart again (for one time, then it disappears again).
I am using a tabactivity if that matters.
btnnumpie = (Button)findViewById(R.id.btnnumpie);
btnnumpie.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
dialog_num = new Dialog(Summary.this);
dialog_num.setContentView(R.layout.dialog_pie_numdur);
dialog_num.setTitle("Pie Chart");
dialog_num.setCancelable(true);
CategorySeries series = new CategorySeries("Number of calls");
series.add("Incoming (" + 20 + "%)" , 20);
series.add("Outgoing (" + 50 + "%)" , 50);
series.add("Missed (" +20 + "%)" , 20);
int[] colors = new int [] {Color.rgb(33, 115, 6), Color.rgb(27, 82, 171), Color.rgb(206, 13, 13)};
DefaultRenderer renderer = new DefaultRenderer();
for (int color: colors){
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
renderer.setFitLegend(true);
renderer.setLabelsColor(Color.BLACK);
renderer.setLabelsTextSize(16);
renderer.setShowLegend(false);
if (mChartView == null) {
LinearLayout graphpie = (LinearLayout)dialog_num.findViewById(R.id.graphpie);
mChartView = ChartFactory.getPieChartView(Summary.this, series, renderer);
graphpie.addView(mChartView, new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
} else {
mChartView.repaint();
}
dialog_num.show();
}
});
I replaced this
to this: