I have a plot attached to wxPanel created using the library wxmathplot, the plot is working fine, I wanted to make the plot change with wxChoice, means there will be several data sets to plot, and I switch between them using wxChoice. I imagine the process to be:
my problem is that the plotting area is not clearing even I used
wxPanel->DestroyChildren(); // and create it again
// or using
mpWindow->DelAllLayers(true);
my question is how to clear plots to update data sets.
The easy way that I found was to attach the plot mpWindow to a panel and set it in a sizer, then create another mpWindow with the new data and replace the old object with the new one:
//the original plot
mpWindow* old_plot = new mpWindow(wxPanel, -1);
// the plot is filled with all the required layers.
panel_sizer->Add(old_plot);
// on changing the plot we create new one:
mpWindow* new_plot = new mpWindow(wxPanel,-1);
// fill all required layers
sizer->Replace(old_plot,newPlot);
old_plot->Destroy();
old_plot = new_plot;