wxFreeChart vs wxMathPlot

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
b_grottier
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Jul 30, 2010 6:19 am

wxFreeChart vs wxMathPlot

Post by b_grottier » Wed Sep 01, 2010 3:07 pm

Hello,

I would like to create 2D charts : histogram, scatter diagrams... I am working with wxWidgets 2.9.1.

I noticed wxFreeChart and wxMathPlot among others. Which one do you use and why ? (I am looking for simple components.)

Thank you for your help.

Benoît

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2293
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Post by evstevemd » Fri Sep 03, 2010 8:09 am

wxFreeChart. I have never used any of those but I think projet is well alive. I tried sometime ago and failed because there was no tutorial for beginners.

If you succeed with your project please take time to write jump start tutorial
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

b_grottier
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Jul 30, 2010 6:19 am

Post by b_grottier » Tue Sep 07, 2010 6:40 am

I eventually chose wxFreeChart because I needed histograms. I do not think that wxMathPlot handles them.
I tried sometime ago and failed
Where did you fail exactly ? I do not have time to write a tutorial but I can help if needed.

Regards,

Benoît

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2293
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Post by evstevemd » Wed Sep 08, 2010 5:55 am

b_grottier wrote:I eventually chose wxFreeChart because I needed histograms. I do not think that wxMathPlot handles them.
I tried sometime ago and failed
Where did you fail exactly ? I do not have time to write a tutorial but I can help if needed.

Regards,

Benoît
Thanks Beno,
I wanted to write an app that ws to plot data in graphs and save as images from massive CSV files. I didn't knew which classes to use for plotting any graph. Its like, if let say you want to write wx program you create parent window (which is top level window) and then create an instance on wxApp derived class and there you are.

I was looking for same intro to wxFreeChart and I found none. Samples were too complex for me. I'll be happy to see few simple examples on how to draw histogram and something like O'give

Thanks
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

b_grottier
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Jul 30, 2010 6:19 am

Post by b_grottier » Wed Sep 08, 2010 7:15 am

First of all, did you manage to build wxFreeChart ? Which OS do you use ? The readme file explains how to create the libraries. If you use Visual Studio, you will find in the build directory some VS projects to compile the libraries.

For the moment, I just defined my own panel based on an example provided with wxFreeChart:

Code: Select all

MyPanel::MyPanel(wxFrame *frame, int x, int y, int w, int h)
       : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
{
	wxBoxSizer * sz = new wxBoxSizer( wxVERTICAL ) ;


	// first serie data
	double data1[][2] = {
				{ 10, 20, },
				{ 13, 16, },
				{ 7, 30, },
				{ 15, 34, },
				{ 25, 4, },
		};
	
	// second serie data
	double data2[][2] = {
				{ 45, 40, },
				{ 23, 16, },
				{ 43, 60, },
				{ 25, 7, },
				{ 66, 4, },
		};

	// first step: create plot
	XYPlot *plot = new XYPlot();

	// create dataset
	XYSimpleDataset *dataset = new XYSimpleDataset();

	// and add to series to it
	dataset->AddSerie((double *) data1, WXSIZEOF(data1));
	dataset->AddSerie((double *) data2, WXSIZEOF(data2));

	// set line renderer with symbols enabled and lines disabled
	dataset->SetRenderer(new XYLineRenderer(true, false));
// 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("First"));
		dataset->SetSerieName(1, wxT("Second"));

		// set legend to plot
		plot->SetLegend(new Legend(wxCENTER, wxRIGHT));

		wxChartPanel * m_chartPanel = new wxChartPanel(this);
		m_chartPanel->SetChart(new Chart(plot)) ;

		sz->Add(m_chartPanel, 1, wxEXPAND );

	SetSizerAndFit(sz) ;
}
I have not tried histograms yet. Nonetheless, I hope this will help you.

Benoît

AUser
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 26, 2006 12:18 am

Post by AUser » Wed Sep 08, 2010 6:21 pm

I quite recommend mathgl (mathgl.sourceforge.net). Its pretty good, but you will need to build your own interaction widget.

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2293
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Post by evstevemd » Thu Sep 09, 2010 5:18 am

b_grottier wrote:First of all, did you manage to build wxFreeChart ? Which OS do you use ? The readme file explains how to create the libraries. If you use Visual Studio, you will find in the build directory some VS projects to compile the libraries.

For the moment, I just defined my own panel based on an example provided with wxFreeChart:

Code: Select all

MyPanel::MyPanel(wxFrame *frame, int x, int y, int w, int h)
       : wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
{
	wxBoxSizer * sz = new wxBoxSizer( wxVERTICAL ) ;


	// first serie data
	double data1[][2] = {
				{ 10, 20, },
				{ 13, 16, },
				{ 7, 30, },
				{ 15, 34, },
				{ 25, 4, },
		};
	
	// second serie data
	double data2[][2] = {
				{ 45, 40, },
				{ 23, 16, },
				{ 43, 60, },
				{ 25, 7, },
				{ 66, 4, },
		};

	// first step: create plot
	XYPlot *plot = new XYPlot();

	// create dataset
	XYSimpleDataset *dataset = new XYSimpleDataset();

	// and add to series to it
	dataset->AddSerie((double *) data1, WXSIZEOF(data1));
	dataset->AddSerie((double *) data2, WXSIZEOF(data2));

	// set line renderer with symbols enabled and lines disabled
	dataset->SetRenderer(new XYLineRenderer(true, false));
// 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("First"));
		dataset->SetSerieName(1, wxT("Second"));

		// set legend to plot
		plot->SetLegend(new Legend(wxCENTER, wxRIGHT));

		wxChartPanel * m_chartPanel = new wxChartPanel(this);
		m_chartPanel->SetChart(new Chart(plot)) ;

		sz->Add(m_chartPanel, 1, wxEXPAND );

	SetSizerAndFit(sz) ;
}
I have not tried histograms yet. Nonetheless, I hope this will help you.

Benoît
Compiling wasn't a problem.
Thanks for snippet. I will try in these few days AND i WILL POST BACK. (My Laptop is out for maintanance about a month. It got a serious screen bug :))
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

Post Reply