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. QtCharts recalculate/update axis for new series values
Forum Update on Monday, May 27th 2025

QtCharts recalculate/update axis for new series values

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtchartsaxis qchartupdate
2 Posts 1 Posters 1.7k 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.
  • P Offline
    P Offline
    pauledd
    wrote on 25 Nov 2019, 15:44 last edited by
    #1

    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
    0
    • P Offline
      P Offline
      pauledd
      wrote on 25 Nov 2019, 16:25 last edited by
      #2

      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
      0

      2/2

      25 Nov 2019, 16:25

      • Login

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