清除 wxmathplot mpWindow 中的绘图?

问题描述 投票:0回答:1

我有一个使用 wxmathplot 库创建的 wxPanel 附加绘图,该绘图工作正常,我想使用 wxChoice 更改绘图,这意味着将有多个数据集要绘制,我使用 wxChoice 在它们之间切换。我想象的过程是:

  • 选择数据集
  • 从之前的绘图中清除绘图区域(mpWindow)
  • 生成新情节

我的问题是即使我使用了绘图区域也没有清除

wxPanel->DestroyChildren(); // and create it again
// or using
mpWindow->DelAllLayers(true);

我的问题是如何清除绘图以更新数据集。

c++ wxwidgets wxmathplot
1个回答
0
投票

我发现的简单方法是将绘图 mpWindow 附加到面板并将其设置在 sizer 中,然后使用新数据创建另一个 mpWindow 并用新对象替换旧对象:

//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;
© www.soinside.com 2019 - 2024. All rights reserved.