Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QChart setting axis

    General and Desktop
    1
    1
    136
    Loading More Posts
    • 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
      Bert59 last edited by

      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 Reply Quote 0
      • First post
        Last post