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. How can i remove qchart unuseful area?
Forum Updated to NodeBB v4.3 + New Features

How can i remove qchart unuseful area?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 601 Views
  • 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.
  • B Offline
    B Offline
    bossman48
    wrote on last edited by
    #1

    Hi,
    I am beginner in Qt. Firstly, I want to build a line chart which starts from first pixel of QFrame , end last pixel of QFrame. I attached a picture. In this picture, how i can remove the area which is described with red arrows.

    Secondly, i want to add a axis for chart. the axis normally goes to 0,....,n(left to right). but i want to build an axis start right to left. i am using the negative point of the QLineSeries. Is it ok? Do you know any solution except mine?

    Finally, in my x axis, i want to seperate a fixed value. In other words, the x axis is have 800 point in every time. If i add 2 point to series, it display 2 point on 800 point. If i add 500 point to series, it display 500 point on 800 point. It may be not clear, because of that i attached a picture. I am send the code which i am working on. Could you help me? Thank you :)

    Code:

    void MainWindow::lineChart(QFrame *horizontalFrame){

    // set pen for series
    QPen pen(QRgb(0x00aa00));
    pen.setWidth(2);
    
    //try some example datas
    QLineSeries *series = new QLineSeries();
    series->setPen(pen);
    series->append(0,1);
    series->append(-1,4);
    
    //set x axis parameters
    QValueAxis* axisX = new QValueAxis();
    axisX->setRange(-100,0);
    axisX->setLabelsVisible(false);
    axisX->setGridLineVisible(false);
    axisX->setLineVisible(false);
    axisX->setShadesVisible(false);
    axisX->setMinorGridLineVisible(false);
    
    //create chart with attributes
    QChart *chart = new QChart();
    chart->addAxis(axisX,Qt::AlignBottom);
    series->attachAxis(axisX);
    chart->setBackgroundBrush(Qt::white);
    chart->layout()->setContentsMargins(0, 0, 0, 0);
    chart->setBackgroundRoundness(0);
    chart->setMaximumSize(810,100);
    chart->setMinimumSize(810,100);
    chart->setPreferredSize(810,100);
    chart->addSeries(series);
    chart->legend()->hide();
    
    //create chartview with some attributes
    QChartView *chartview = new QChartView(chart);
    chartview->setRenderHint(QPainter::Antialiasing);
    chartview->setParent(horizontalFrame);
    chartview->setContentsMargins(0,0,0,0);
    

    }

    removeAreaFromChart_2.png

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Take a look at QChart::margins()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      B 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Take a look at QChart::margins()

        B Offline
        B Offline
        bossman48
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thank you :) How can split x axis to 800 fixed point? Do you know anything about this subject? Thank you again :)

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QChart is a QGraphicsWidget so https://doc.qt.io/qt-5/qgraphicswidget.html#size-prop maybe?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          B 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            QChart is a QGraphicsWidget so https://doc.qt.io/qt-5/qgraphicswidget.html#size-prop maybe?

            B Offline
            B Offline
            bossman48
            wrote on last edited by
            #5

            @Christian-Ehrlicher Thank you for quick reply, i have tried but not working :( 2 data point completely envelop the chart like previously.
            Thank you so much :)

            1 Reply Last reply
            0

            • Login

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