Showing temperature in a graph.



  • Im making a GPU Temp app for linux And I would like too add a graph. I think Qt has no widget for showing graph so I should make a widget myself.

    I already tried making cosine graph(just for testing) and i couldn't get good results (like the system monitor on linux)
    I first tried calculating Y for each x and keeping the old Y so i can draw a line from the oldY to newY while it worked, it wasn't good looking.

    How can I make a good looking graph widget?



  • Have you tried qwt?



  • @mrdebug No! i will give it a try, but just wondering, what should i do if i wanted to make a graph widget myself?

    edit:
    i get this when trying to install qwt on ubuntu 14.04 lts!

    cd src/ && make -f Makefile
    make[1]: Entering directory /home/k/Documents/qwt-6.1.2/src' compiling qwt_abstract_scale_draw.cpp In file included from qwt_abstract_scale_draw.h:13:0, from qwt_abstract_scale_draw.cpp:10: qwt_global.h:13:21: fatal error: qglobal.h: No such file or directory #include <qglobal.h> ^ compilation terminated. make[1]: *** [obj/qwt_abstract_scale_draw.o] Error 1 make[1]: Leaving directory/home/k/Documents/qwt-6.1.2/src'
    make: *** [sub-src-make_default-ordered] Error 2


  • Moderators

    @kamhagh said:

    **cd src/ && make -f Makefile

    How did you generate that Makefile?

    Open qwt.pro in Qt Creator and build there.



  • You can make one yourself. You need to get the math right or it will be a mess. This is the important parts for how I did mine:

    // this is the TViewportMat that is used
    
    struct TViewportMat
    {
    	double								tx[2];
    	double								ty[2];
    	double								to[2];
    
    	TViewportMat& operator*=(const TViewportMat &rhs)
    	{
    		double							x,y,o[2];
    
    		x = tx[0] * rhs.tx[0];
    		y = ty[1] * rhs.ty[1];
    		o[0] = to[0] * rhs.tx[0] + rhs.to[0];
    		o[1] = to[1] * rhs.ty[1] + rhs.to[1];
    
    		tx[0] = x;
    		ty[1] = y;
    		to[0] = o[0];
    		to[1] = o[1];
    
    		return *this;
    	}
    
    	void TranslateToWin(const double Xd, const double Yd, int *X, int *Y) const
    	{
    		*X = static_cast<int>(Xd * tx[0] + to[0]);
    		*Y = static_cast<int>(Yd * ty[1] + to[1]);
    	}
    
    	void TranslateFromWin(const int X,const int Y,double *Xd,double *Yd) const
    	{
    		*Xd = (static_cast<double>(X) - to[0]) / tx[0];
    		*Yd = (static_cast<double>(Y) - to[1]) / ty[1];
    	}
    };
    
    
    // This updates an instance of 'TViewportMat' based on a combination of your data (the X and Y range) and the size of the widget area you plan to draw on.
    
    void TGraphWidget::CalculateViewport(void)
    {
        double                              MinX,MaxX,MinY,MaxY,RangeX,RangeY
        TViewportMat                        W,S,V;
     
    // find values for MinX, MaxX, MinY, MaxY from your data
    // make sure difference between Min and Max limits has a minimum value.  I use 0.00005.
    // add a margin by increasing the Min and Max limits slightly
    	
        W.tx[0] = 1;
        W.tx[1] = 0;
        W.ty[0] = 0;
        W.ty[1] = 1;
        W.to[0] = -MinX;
        W.to[1] = -MinY;
    
    // d_GraphRect is the rect for the area the graph occupies.
    // should be the area of the widget or at least the part the graph will occupy
    
        S.tx[0] = (d_GraphRect.right() - d_GraphRect.left()) / (MaxX - MinX);
        S.tx[1] = 0;
        S.ty[0] = 0;
        S.ty[1] = (d_GraphRect.top() - d_GraphRect.bottom()) / (MaxY - MinY);
        S.to[0] = 0;
        S.to[1] = 0;
    
        V.tx[0] = 1;
        V.tx[1] = 0;
        V.ty[0] = 0;
        V.ty[1] = 1;
        V.to[0] = d_GraphRect.left();
        V.to[1] = d_GraphRect.bottom();
    
        d_ViewportMat = W;
        d_ViewportMat *=S;
        d_ViewportMat *=V;    
    }
    
    // To draw onto the graph area use something like this:
    
    	d_ViewportMat.TranslateToWin(input_data_x,input_data_y,&X,&Y);
    							
    	Painter->drawLine(LastX,LastY,X,Y);
    	LastX = X;
    	LastY = Y;
    

    The member 'TranslateToWin' will convert your input data into window coordinates that you can use to draw with. The member 'TranslateFromWin' takes window coordinates and converts to the graph (I use this to display coordinates when my mouse moves over the graph).



  • @Rondog I've no idea what any of those mean! I rather just stick to qwt now!

    edit: after copying it to a code editor now i understand! my brain freezes when i see code without color! :D thanks!



  • @JKSH I get this when i use Qt Creator:
    :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install
    My qt creator version is 3.1.2 (based on Qt 3.2.1) its old but i had problems downloading the new version after they changed the website

    and i just ran the .run file i downloaded from the website when i installed it


  • Moderators

    @kamhagh said:

    @JKSH I get this when i use Qt Creator:
    :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install

    How do you write Qt apps if your installation is broken?



  • @JKSH
    I've no idea! All i did was downloading the lastest qt from the website (at the time it was 5.3.1) and runing the .run file from terminal! thats it! i've been programming without any problems since then!



  • @JKSH Oh sorry, i get that when i try to compile it, not when i start qt creator, it actually starts without any errors!


  • Moderators

    @kamhagh said:

    @JKSH Oh sorry, i get that when i try to compile it, not when i start qt creator, it actually starts without any errors!

    Ok, then compile qwt.pro the same way as how you compile your other Qt projects..



  • @JKSH i press the run button and it gives me this! (with the file open and the project configured)

    My Qt creator starts without any errors, once I open the file you mentioned in Qt Creator it asks me to configure it, so I press configure and run it, then it gives me the error I posted before.



  • After re unpacking the package it now works! let me check the installing page to see what to do next!
    Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.