Important: Please read the Qt Code of Conduct -

QtCharts recalculate/update axis for new series values

  • 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->addAxis(xAxis, Qt::AlignBottom);
        chart->addAxis(yAxis, Qt::AlignLeft);
    void PlotWindow::updatePlot(const QVector<double> &dat)
        for(int i=0;i<dat.size();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?

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