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 to display rectangle on a graph at a specific location.
Forum Updated to NodeBB v4.3 + New Features

How to display rectangle on a graph at a specific location.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 976 Views 1 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.
  • P Offline
    P Offline
    preddy
    wrote on last edited by
    #1

    I need to create a graph that displays rectangles that can be changed depending upon the user input values. And the rectangle should contain text.

    I used QAreaSeries to display a rectangle but there's no function to type text over it. I need to add a rectangle to the same graph every time that function is called.

    The first image is how I want to display.

    The second image is how my code displays the rectangle.

    QChart *qChart = new QChart();
    QChartView *myChartView = new QChartView(qChart);
    QValueAxis *qAxisX = new QValueAxis;
    QValueAxis qAxisY = new QValueAxis;
    qAxisX->setRange(0, 30);
    qAxisY->setRange(0, ending_height_of_rect
    2);

    QLineSeries *series0 = new QLineSeries();
    QLineSeries *series1 = new QLineSeries();

    *series0 << QPointF(1, starting_point_of_rectangle) << QPointF(1, ending_height_of_rect);
    *series1 << QPointF(4, starting_point_of_rectangle) << QPointF(4, ending_height_of_rect);

    QAreaSeries *series = new QAreaSeries(series0, series1);
    myChartView->chart()->addSeries(series);
    qChart->setAxisX(qAxisX, series);
    qChart->setAxisY(qAxisY, series);

    ui->verticalLayout->addWidget(myChartView);

    Annotation1.png

    Annotation 2.png

    Please let me know if I can use any other method instead of QAreaSeries which helps me get this work done a lot more easily.

    Any type of help is appreciated.

    Thank you.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I think you can reuse this example
      https://doc.qt.io/qt-5/qtcharts-callout-example.html

      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