Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Unsolved QtCharts recalculate/update axis for new series values

    General and Desktop
    qtcharts axis qchart update
    1
    2
    933
    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.
    • pauledd
      pauledd last edited by

      Hi

      I have a slot function updatePlot(...) that receives a QVector<double> and iterates through the vector data
      and fills a series which has been cleared prior.

      {
      ...
          ls = new QLineSeries();
          chart = new QChart();
          xAxis = new QValueAxis;
          yAxis = new QValueAxis;
          cv = new QChartView(chart);
      
          chart->addSeries(ls);
          chart->addAxis(xAxis, Qt::AlignBottom);
          chart->addAxis(yAxis, Qt::AlignLeft);
          ls->attachAxis(xAxis);
          ls->attachAxis(yAxis);
      ...
      }
      ...
      void PlotWindow::updatePlot(const QVector<double> &dat)
      {
          ls->clear();
          for(int i=0;i<dat.size();i++){
      	ls->append(i,dat.at(i));
          }
      }
      

      The problem of course is now that the data changes x and y ranges every time, but the axes
      stay at the same range. What is the proper way to recalculate the x/y axes ranges?

      Do I have to take care of it and calculate the high/low values in the for loop or is there a function in the qtcharts that does this for me?

      1 Reply Last reply Reply Quote 0
      • pauledd
        pauledd last edited by

        so for now I use this which seems to work...

        xAxis->setRange(0,dat.size());
        yAxis->setRange(*std::min_element(dat.constBegin(),dat.constEnd()),*std::max_element(dat.constBegin(),dat.constEnd()));
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post