wxfreechart delete dataset

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
seabug
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Nov 27, 2018 10:29 am

wxfreechart delete dataset

Post by seabug » Tue Nov 27, 2018 10:39 am

Hi guys,

I am using wxfreechart to create a simple 2D line chart. Everything is working fine with the first chart,
but I could not find any way to "reset" the chart. So I started to delete the plot,dataset and wxChartPanel.
It worked on BSD, but when I tried to do the same on Raspbian, I get a memory violation error.
I tried clang and gcc.
Can anyone help ? Is there another way to reset the chart/dataset ?

Best regards,
Steffen

Code: Select all

 XYPlot *plot;
 XYSimpleDataset *dataset;
double data1[0][2];
wxChartPanel * m_chartPanel;
 
void MFR::CreateChart(int firsttime) {
	if (firsttime == 0) {
		delete plot;
		delete dataset;
//delete[] dataset; doesn't work too
//wxDELETE(dataset); doesn't work too
		m_chartPanel->Destroy();
	}

	data1[0][0] = 0;
	data1[0][1] = 0;

	// first step: create plot
//	XYPlot *plot = new XYPlot();
	plot = new XYPlot();
	// create dataset
//	XYSimpleDataset *dataset = new XYSimpleDataset();
	dataset = new XYSimpleDataset();
	// and add to series to it
	dataset->AddSerie((double *) data1, WXSIZEOF(data1));
// set line renderer with symbols enabled and lines disabled
	dataset->SetRenderer(new XYLineRenderer(false, true));
// add our dataset to plot
	plot->AddDataset(dataset);
// create left and bottom number axes
	plot->AddAxis(new NumberAxis(AXIS_LEFT));
	plot->AddAxis(new NumberAxis(AXIS_BOTTOM));
// link axes and dataset
	plot->LinkDataVerticalAxis(0, 0);
	plot->LinkDataHorizontalAxis(0, 0);
// set serie names to be displayed on legend
//	dataset->SetSerieName(0, wxT("P"));
// set legend to plot
//	plot->SetLegend(new Legend(wxCENTER, wxRIGHT));
	wxChartPanel * m_chartPanel = new wxChartPanel(this, ID_FrmChart, NULL, wxPoint(1, 1), wxSize(398, 510));
	m_chartPanel->SetChart(new Chart(plot));
}
Last edited by catalin on Tue Nov 27, 2018 10:43 am, edited 1 time in total.
Reason: code tags

seabug
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Nov 27, 2018 10:29 am

Re: wxfreechart delete dataset

Post by seabug » Tue Nov 27, 2018 7:43 pm

I finally found a solution by myself.
I used VectorDataset instead of XYSimpleDataset.
VectorDataset->Clear();

Post Reply