2D-Plots  [SOLVED]

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.
wxJack
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Jun 20, 2018 8:06 am

Re: 2D-Plots

Postby wxJack » Mon Jul 09, 2018 9:03 pm

Yes, but in a separate project in order to check If my wxFreeChart settings were all correct, but they're not.
I think something in my settings is wrong/missing but I don't know what exactly.

I tried nmake -fmakefile.vc WX_DIR=C:\wxWidgets WX_UNICODE=1 WX_DEBUG=0 WX_SHARED=0 WX_MONOLITHIC=0 WX_VERSION=30 ,
it works (and it worked the first time I tried this) but I still have 5 unresolved externals

User avatar
doublemax
Moderator
Moderator
Posts: 12604
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 2D-Plots

Postby doublemax » Mon Jul 09, 2018 9:27 pm

All the missing references are not from the core freechart library, they are in one of the sample files (democollection.cpp). What exactly are you building?
Use the source, Luke!

wxJack
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Jun 20, 2018 8:06 am

Re: 2D-Plots

Postby wxJack » Tue Jul 10, 2018 12:14 pm

Yes, I was building demo.cpp along with demo.h and democollection.h (because both are included in the cpp file) , without democollection.cpp ;
now, building the project with also the inclusion of democollection.cpp , I have 22 unserolved externals ; all the lines of the output
are something like this : "democollection.obj : error LNK2001: unresolved external symbol "class ChartDemo * * markersDemos" (?markersDemos@@3PAPAVChartDemo@@A) "

User avatar
mill-j
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 02, 2018 3:21 pm

Re: 2D-Plots

Postby mill-j » Tue Jul 10, 2018 12:39 pm

All of the files in the sample folder are needed to build the demo. I'd really recommend starting a separate app and copying and modifying code for the graph you need from demo(I doubt you need them all). If you plan on manually building demo, check out the makefiles for it, they might have some pointers.
[-X Don't Complain, Change It, It's Open-Source!

wxJack
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Jun 20, 2018 8:06 am

Re: 2D-Plots

Postby wxJack » Tue Jul 10, 2018 1:14 pm

Ooh, now I understand! thank you very much @mill-j!
I was wasting my time trying to build only a part!
In order to learn how to make easy 2d-graphs, do you suggest to study the demo sample or other tutorials?

User avatar
mill-j
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 02, 2018 3:21 pm

Re: 2D-Plots

Postby mill-j » Tue Jul 10, 2018 2:00 pm

The sample is awesome, but it is huge. I recommend that you figure out which graph you want (e.g. bar graph) and create a minimal wxWidgets app then copy only the functions related to the graph you need, this will take time and tweaks but trust me it works. The online documentation on the wxCode website helps a lot too.

Good Luck
[-X Don't Complain, Change It, It's Open-Source!

wxJack
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Jun 20, 2018 8:06 am

Re: 2D-Plots

Postby wxJack » Thu Jul 12, 2018 4:00 pm

thank you! I'm trying to do what you suggested .
In the meantime , I also looked at this tutorial https://iwbnwif.github.io/freechart_doc ... index.html
but i don't understand one thing; at the step number 5 of the tutorial, they write

Code: Select all

// Normal wxWidgets form / dialog / sizer stuff goes here, e.g.:
"m_pMainSizer->Add(chartPanel, 1, 1, 5); "


But in my OnInit method, when I write

Code: Select all

topSizer1->Add(chartPanel,1,1,5);
,
where topSizer1 is a wxBoxSizer, I have this error : error C2664: 'wxSizerItem *wxSizer::Add(wxSizerItem *)': cannot convert argument 1 from 'wxChartPanel *(__cdecl *)(Chart)' to 'wxWindow *' .
Has anyone idea of what I can do to fix it?
thanks a lot

User avatar
mill-j
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 02, 2018 3:21 pm

Re: 2D-Plots

Postby mill-j » Thu Jul 12, 2018 6:10 pm

[-X You need to add your chart to the frame. Here is a modified minimal app that I cobbled together just now.

Code: Select all

#include <wx/wx.h>
#include <wx/bars/barplot.h>
#include <wx/chartpanel.h>
#include <wx/axis/numberaxis.h>
#include <wx/axis/categoryaxis.h>
#include <wx/xy/xyhistorenderer.h>
#include <wx/category/categorysimpledataset.h>

// Define a new application type, each program should derive a class from wxApp
class MyApp : public wxApp
{
public:
    // override base class virtuals
    // ----------------------------

    // this one is called on application startup and is a good place for the app
    // initialization (doing it here and not in the ctor allows to have an error
    // return: if OnInit() returns false, the application terminates)
    virtual bool OnInit();
};

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    // ctor(s)
    MyFrame(const wxString& title);
   wxChartPanel* GraphChartPanel;
   void ShowGraph();

private:
    // any class wishing to process wxWidgets events must use this macro
    //wxDECLARE_EVENT_TABLE();
};

wxIMPLEMENT_APP(MyApp);


bool MyApp::OnInit()
{
    // call the base class initialization method, currently it only parses a
    // few common command-line options but it could be do more in the future
    if ( !wxApp::OnInit() )
        return false;

    // create the main application window
    MyFrame *frame = new MyFrame("Minimal wxWidgets App");

    // and show it (the frames, unlike simple controls, are not shown when
    // created initially)
    frame->Show(true);

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}

// frame constructor
MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
   
   wxBoxSizer* bSizer1;
   bSizer1 = new wxBoxSizer( wxVERTICAL );

   GraphChartPanel = new wxChartPanel(this,-1);
   bSizer1->Add(GraphChartPanel, 1,wxALL|wxEXPAND, 5);
   
   this->SetSizer( bSizer1 );
   this->Layout();
   
   this->Centre( wxBOTH );
   
   ShowGraph();
}

void MyFrame::ShowGraph()
{
   double values1[5];
   wxString names[5];
   
   values1[0] = 12;
   values1[1] = 50;
   values1[2] = 90;
   values1[3] = 20;
   values1[4] = 100;
   
   names[0] = "Sample1";
   names[1] = "Sample2";
   names[2] = "Sample3";
   names[3] = "Sample4";
   names[4] = "Sample5";
   
      // Create dataset
    CategorySimpleDataset *dataset = new CategorySimpleDataset(names, WXSIZEOF(names));

    // add serie to it
   
    dataset->AddSerie(wxT("First Bar"), values1, WXSIZEOF(values1));

    // create layered bar type with width=40 and base=0
    BarType *barType = new LayeredBarType(40, 0);

    // Set bar renderer for it, with layered bar type
    BarRenderer *renderer = new BarRenderer(barType);

    // Some eye-candy: gradient bars
    renderer->SetBarDraw(0, new GradientAreaDraw(*wxBLUE, wxColor(0,171,255),
                                                    wxColor(0,171,255).ChangeLightness(150), wxNORTH));
                                                   
    // assign renderer to dataset
    dataset->SetRenderer(renderer);

    // Create bar plot
    BarPlot *plot = new BarPlot();

    // Add left category axis
    NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT);
    leftAxis->SetMargins(0, 0);
    plot->AddAxis(leftAxis);

    // Add bottom number axis
    CategoryAxis *bottomAxis = new CategoryAxis(AXIS_BOTTOM);
    bottomAxis->SetMargins(20, 20);
    plot->AddAxis(bottomAxis);

    // Add dataset to plot
    plot->AddDataset(dataset);

    // Link first dataset with first horizontal axis
    plot->LinkDataHorizontalAxis(0, 0);

    // Link first dataset with first vertical axis
    plot->LinkDataVerticalAxis(0, 0);
   
    //test
    Legend* legend = new Legend(wxCENTER, wxRIGHT, new FillAreaDraw(*wxTRANSPARENT_PEN, *wxTRANSPARENT_BRUSH));
    plot->SetLegend(legend);

    // and finally construct and return chart
    GraphChartPanel->SetChart(new Chart(plot, "TITLE"));
}


It took me awhile to figure out wxFreeChart myself, hopefully this helps.

I'd really recommend you take the time and study the wxWidgets documentation, once you figure out the syntax there's almost nothing you can't figure out.
[-X Don't Complain, Change It, It's Open-Source!

wxJack
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Jun 20, 2018 8:06 am

Re: 2D-Plots

Postby wxJack » Fri Jul 13, 2018 3:46 pm

It helped, thank you very much.
You're right, I have to take my time to study more and better this new world.
really appreciated your help

iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 263
Joined: Tue Mar 19, 2013 8:52 pm

Re: 2D-Plots

Postby iwbnwif » Mon Jul 16, 2018 5:49 pm

Hi,

I have been away from the forum for a few weeks and missed this topic before now.

Sadly, I haven't been able to work on any updates to wxFreeChart for quite a while, but I really hope that will change later in the year and I can again spend some time on the project.

Please do raise an issue for any problems you find or if you think it is possible to improve something. Of course pull requests to solve the issues are very welcome!

:)
wxWidgets 3.10, TDM MinGW64 5.1.0, g++ 4.8.2, Ubuntu 16.04LTS, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.

wxJack
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Jun 20, 2018 8:06 am

Re: 2D-Plots

Postby wxJack » Tue Jul 17, 2018 9:43 am

@mill-j , @iwbn
thanks for posting!

I think I've found an issue.
Considering the code of @mill-j ,
With these 2 lines

Code: Select all

const wxPoint pos1 = wxPoint(300, 400);
   GraphChartPanel = new wxChartPanel(this, wxID_ANY, 0, pos1 , { 500,500 });


I want to put my graph in a precise point and set a precise size..The size works fine, I can choose every size I want..but the position
is always the wxDefaultPosition even if I try to change it...has anyone found this issue too?
Many many thanks guys

iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 263
Joined: Tue Mar 19, 2013 8:52 pm

Re: 2D-Plots

Postby iwbnwif » Tue Jul 17, 2018 11:02 am

wxChartPanel is subclassed from wxScrolledWindow, aka wxScrolled<wxPanel> in recent versions of wxWidgets.

So the behavior will be the same as for wxScrolledWindow in this respect.

I always use sizers so haven't tried with fixed positioning, however if you are adding the wxChartPanel to a sizer then it is possible that the position value is being ignored.

I would strongly recommending using sizers rather than discrete positions with wxWidgets.

Just in case you didn't read it already, take a look at the overview here: http://docs.wxwidgets.org/3.1/overview_sizer.html or search "wxWidgets sizer tutorial".
wxWidgets 3.10, TDM MinGW64 5.1.0, g++ 4.8.2, Ubuntu 16.04LTS, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.

User avatar
mill-j
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 02, 2018 3:21 pm

Re: 2D-Plots

Postby mill-j » Tue Jul 17, 2018 12:53 pm

@wxJack I agree, you'll be better off in the long run figuring out sizers. The app that helped me get the "concept" was https://github.com/wxFormBuilder/wxFormBuilder wxFormBuilder

@iwbnwif Thanks for maintaining such a great library. One thing that comes to mind, could you modify the ./configure system to allow wxQT builds even if it doesn't currently build under that platform? Or maybe give some advice on how to accomplish this, to me the build system looks complicated :D
[-X Don't Complain, Change It, It's Open-Source!

iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 263
Joined: Tue Mar 19, 2013 8:52 pm

Re: 2D-Plots

Postby iwbnwif » Wed Jul 18, 2018 1:15 pm

@mill-j I haven't used wxQT before but I will try to take a look at it at some point.

I too am not a fan of the ./configure build generator (Autotools?) but the popular alternative (CMake) doesn't seem much better. I guess I will have to bite the bullet at some point and learn one or the other properly.

For the moment I have a project setup in Codelite which I find very straightforward and reliable.
wxWidgets 3.10, TDM MinGW64 5.1.0, g++ 4.8.2, Ubuntu 16.04LTS, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.

User avatar
mill-j
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 02, 2018 3:21 pm

Re: 2D-Plots

Postby mill-j » Fri Jul 20, 2018 1:17 am

Ok never mind. I got it. I had to download the build/autoconf files from here https://sourceforge.net/p/wxcode/code/H ... Code/build and edit the wxwin.m4 file to allow wxQT, then rebuild the configure file.

I also built the wxFreeChart against wxQT and it built with no errors the first time around :shock: , however I do get errors when linking against the FreeChart lib. This means the demo doesn't build yet. No big deal, I can start tinkering now and see what needs fixing.

EDIT: I was wrong! It does link(I forget to export LD_LIBRARY_LIBS) Most charts are lacking bars, etc but the pie chart works;)
2018-07-19Thu1521.png
wxFreeChart built against wxQT
2018-07-19Thu1521.png (32.94 KiB) Viewed 249 times
[-X Don't Complain, Change It, It's Open-Source!


Return to “C++ Development”

Who is online

Users browsing this forum: Google [Bot], raananb and 25 guests