Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Line graph Plot in Qdialog
Forum Updated to NodeBB v4.3 + New Features

Line graph Plot in Qdialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 5.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Meenu
    13 Aug 2016, 11:19

    how to add manually

    ? Offline
    ? Offline
    A Former User
    wrote on 13 Aug 2016, 11:44 last edited by
    #6

    @Meenu package manager

    1 Reply Last reply
    0
    • M Meenu
      13 Aug 2016, 11:10

      Error QtCharts/QChartView: No such file or directory. Can i install QtChart Separately. I'm using QT Creator 3.5.1 based on QT 5.6.0(GCC 5.3.1 20160413, 32 bit). I was seen this example from Google. but i don't know how to implement. Kindly explain step by step.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Aug 2016, 12:05 last edited by mrjj
      #7

      @Meenu
      hi
      if u only need something really simple. ( ie no zoom etc)
      you can also just draw on an image and show in a Label.

      alternate text

      test project
      https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0

      its few lines of code

      int GetBarHeight(int MAX) {
      return rand() % (MAX - 5) + 5;
      }

      void MainWindow::on_pushButton_released() {
        int h = ui->label->height();
        int w = ui->label->width();
        QPixmap pix(w, h);
        QPainter paint(&pix);
        pix.fill( Qt::white );
        paint.setPen(QColor(0, 0, 0, 255));
        int y = 0;
        int x = 0;
        int bw = 10; // bar width
        for (int barcount = 0; barcount < 12; ++barcount) {
          paint.setBrush(QColor(255 - x, 34 + x, 255, 255));
          paint.drawRect(x, h - GetBarHeight(h),  bw, h );
          x += bw + 4;
        }
        paint.end();
        ui->label->setPixmap(pix);
      }
      
      ? M 2 Replies Last reply 13 Aug 2016, 12:09
      0
      • M mrjj
        13 Aug 2016, 12:05

        @Meenu
        hi
        if u only need something really simple. ( ie no zoom etc)
        you can also just draw on an image and show in a Label.

        alternate text

        test project
        https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0

        its few lines of code

        int GetBarHeight(int MAX) {
        return rand() % (MAX - 5) + 5;
        }

        void MainWindow::on_pushButton_released() {
          int h = ui->label->height();
          int w = ui->label->width();
          QPixmap pix(w, h);
          QPainter paint(&pix);
          pix.fill( Qt::white );
          paint.setPen(QColor(0, 0, 0, 255));
          int y = 0;
          int x = 0;
          int bw = 10; // bar width
          for (int barcount = 0; barcount < 12; ++barcount) {
            paint.setBrush(QColor(255 - x, 34 + x, 255, 255));
            paint.drawRect(x, h - GetBarHeight(h),  bw, h );
            x += bw + 4;
          }
          paint.end();
          ui->label->setPixmap(pix);
        }
        
        ? Offline
        ? Offline
        A Former User
        wrote on 13 Aug 2016, 12:09 last edited by
        #8

        @mrjj Nice color gradient ;-)

        1 Reply Last reply
        1
        • M Meenu
          13 Aug 2016, 11:19

          how to add manually

          ? Offline
          ? Offline
          A Former User
          wrote on 13 Aug 2016, 12:10 last edited by
          #9

          @Meenu This might help you with Ubuntu's package manager: https://help.ubuntu.com/lts/serverguide/apt.html

          M 1 Reply Last reply 16 Aug 2016, 07:08
          1
          • M mrjj
            13 Aug 2016, 12:05

            @Meenu
            hi
            if u only need something really simple. ( ie no zoom etc)
            you can also just draw on an image and show in a Label.

            alternate text

            test project
            https://www.dropbox.com/s/qwde8lb0fkjrrh3/mycheapgraph.zip?dl=0

            its few lines of code

            int GetBarHeight(int MAX) {
            return rand() % (MAX - 5) + 5;
            }

            void MainWindow::on_pushButton_released() {
              int h = ui->label->height();
              int w = ui->label->width();
              QPixmap pix(w, h);
              QPainter paint(&pix);
              pix.fill( Qt::white );
              paint.setPen(QColor(0, 0, 0, 255));
              int y = 0;
              int x = 0;
              int bw = 10; // bar width
              for (int barcount = 0; barcount < 12; ++barcount) {
                paint.setBrush(QColor(255 - x, 34 + x, 255, 255));
                paint.drawRect(x, h - GetBarHeight(h),  bw, h );
                x += bw + 4;
              }
              paint.end();
              ui->label->setPixmap(pix);
            }
            
            M Offline
            M Offline
            Meenu
            wrote on 16 Aug 2016, 05:28 last edited by
            #10

            @mrjj
            I want to plot line graph. so i changed the code like below

            int data[255];
            int i = 0;
            for (i = 0; i < 255; ++i)  data[i] = i;
            for (i = 0; i < 255; ++i)  paint.drawLine(i, data[i], i+1, data[i+1]);
            

            Here How to Set Lable's pixel (0,0) as bottom left corner?
            Now, Graph plotting reversely(Top left corner).

            M V 2 Replies Last reply 16 Aug 2016, 07:04
            0
            • M Meenu
              16 Aug 2016, 05:28

              @mrjj
              I want to plot line graph. so i changed the code like below

              int data[255];
              int i = 0;
              for (i = 0; i < 255; ++i)  data[i] = i;
              for (i = 0; i < 255; ++i)  paint.drawLine(i, data[i], i+1, data[i+1]);
              

              Here How to Set Lable's pixel (0,0) as bottom left corner?
              Now, Graph plotting reversely(Top left corner).

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 16 Aug 2016, 07:04 last edited by
              #11

              @Meenu
              hi
              you can change for painter with
              painter.translate();

              http://doc.qt.io/qt-5/qpainter.html#translate

              its not related to the label at all.
              we draw on image and label just show it :)

              M 1 Reply Last reply 16 Aug 2016, 08:26
              0
              • ? A Former User
                13 Aug 2016, 12:10

                @Meenu This might help you with Ubuntu's package manager: https://help.ubuntu.com/lts/serverguide/apt.html

                M Offline
                M Offline
                Meenu
                wrote on 16 Aug 2016, 07:08 last edited by
                #12

                @Wieland Getting Error - chartdataset.cpp:30:36: fatal error: private/chartdataset_p.h: No such file or directory.
                I was download qtcharts-opensource-src-5.7.0 and installed successfully, like from download directory.

                > qmake
                > sudo make
                

                line chart from examples working good. i like to implement this chart in my QDialog.
                Now, i came to my code and simply add

                #include <QtCharts/QChartView>
                #include <QtCharts/QLineSeries>
                

                how can i link QTChart with my *.Pro File.

                1 Reply Last reply
                0
                • M mrjj
                  16 Aug 2016, 07:04

                  @Meenu
                  hi
                  you can change for painter with
                  painter.translate();

                  http://doc.qt.io/qt-5/qpainter.html#translate

                  its not related to the label at all.
                  we draw on image and label just show it :)

                  M Offline
                  M Offline
                  Meenu
                  wrote on 16 Aug 2016, 08:26 last edited by
                  #13

                  @mrjj Thank you. Its Working.

                  paint.translate(0,h);
                  paint.scale(1.0, -1.0);
                  
                  1 Reply Last reply
                  1
                  • M Meenu
                    16 Aug 2016, 05:28

                    @mrjj
                    I want to plot line graph. so i changed the code like below

                    int data[255];
                    int i = 0;
                    for (i = 0; i < 255; ++i)  data[i] = i;
                    for (i = 0; i < 255; ++i)  paint.drawLine(i, data[i], i+1, data[i+1]);
                    

                    Here How to Set Lable's pixel (0,0) as bottom left corner?
                    Now, Graph plotting reversely(Top left corner).

                    V Offline
                    V Offline
                    VRonin
                    wrote on 16 Aug 2016, 09:44 last edited by VRonin
                    #14

                    @Meenu said:

                    so i changed the code like below

                    for (i = 0; i < 255; ++i)  paint.drawLine(i, data[i], i+1, data[i+1]);
                    

                    If you cannot see the problem there add #include <array> and change int data[255]; into std::array<int,255> data;

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    M 1 Reply Last reply 16 Aug 2016, 10:07
                    0
                    • V VRonin
                      16 Aug 2016, 09:44

                      @Meenu said:

                      so i changed the code like below

                      for (i = 0; i < 255; ++i)  paint.drawLine(i, data[i], i+1, data[i+1]);
                      

                      If you cannot see the problem there add #include <array> and change int data[255]; into std::array<int,255> data;

                      M Offline
                      M Offline
                      Meenu
                      wrote on 16 Aug 2016, 10:07 last edited by
                      #15

                      @VRonin Its plotting random data. nice.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Meenu
                        wrote on 17 Aug 2016, 10:23 last edited by
                        #16

                        After install QTChart / QWT chart controls, is possible to use these controls in to QDialog box.
                        How to link with *.PRO File.
                        QWT link process :

                        QWT_DIR = /usr/local/qwt-6.1.3
                        INCLUDEPATH += $$QWT_DIR/include
                        
                        CONFIG(debug, debug|release):LIBS += -L$$QWT_DIR\lib\ \
                        -lqwtd5
                        else:LIBS += -L$$QWT_DIR\lib\ \
                        -lqwt5
                        
                        DEFINES += QWT_DLL
                        

                        is correct?

                        1 Reply Last reply
                        0

                        15/16

                        16 Aug 2016, 10:07

                        • Login

                        • Login or register to search.
                        15 out of 16
                        • First post
                          15/16
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved