Page 1 of 1

wxfreechart delete dataset

Posted: Tue Nov 27, 2018 10:39 am
by seabug
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,

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

	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
// 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));

Re: wxfreechart delete dataset

Posted: Tue Nov 27, 2018 7:43 pm
by seabug
I finally found a solution by myself.
I used VectorDataset instead of XYSimpleDataset.