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. QChart setting axis
Qt 6.11 is out! See what's new in the release blog

QChart setting axis

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 375 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
    Bert59
    wrote on last edited by
    #1

    Hi,
    I'm a beginner in Qt and have some trouble with the QChart widget.

    Here is my code:
    In the constructor:

    ui->setupUi(this);
    m_chart = ui->graphView->chart();
    
    m_xAxis = new QValueAxis;
    m_xAxis->setMax(1200.0);
    m_xAxis->setMin(0.0);
    m_xAxis->setTitleText("Distance");
    m_chart->addAxis(m_xAxis, Qt::AlignBottom);
    
    m_yAxis = new QValueAxis;
    m_yAxis->setMax(25.0);
    m_yAxis->setMin(-25.0);
    m_yAxis->setTitleText("DDM (µA)");
    m_chart->addAxis(m_yAxis, Qt::AlignLeft);
    m_chart->setTitle("Bend limits");
    

    A pushButton with the following code:

    QLineSeries *series = new QLineSeries();
    m_series.append(series);
    QList<QPointF> data;
    for (int i = 0; i < 360; i++)
    {
       series->append(QPointF(i, Sin(qDegreesToRadians(qreal(i)))));
    }
    m_chart->addSeries(series);
    series->setName("Distances");
    series->attachAxis(m_xAxis);
    series->attachAxis(m_yAxis);
    

    A doubleSpinBox for changing the Axis range with the following code:

    double test = ui->doubleSpinBox->value();
    m_xAxis->setRange(0.0, test);
    

    The problem is that each time I change the m_xAxis range a new plot is added.

    First click on Draw button
    8825ed19-4c06-4edf-913b-38e1f624dbaa-image.png

    Setting X max value to 600
    062dd58e-99d0-4986-94d1-39bc9467b9c4-image.png

    What is the reason for this behavior and how can I get rid of it?
    Thank you

    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