Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Unsolved QChart : Update\rescale axis after series update

    General and Desktop
    2
    3
    6875
    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
      bronstein87 last edited by bronstein87

      So, how can i update axis after series update?
      Example. Here i create chart:

      QChartView* view;
          QChart* chart= new QChart();
          QLineSeries *series = new QLineSeries();
          for(int i=0;i<50000;i++)
          {
              series->append(i,i);
          }
          chart->addSeries(series);
      QDateTimeAxis *axisX = new QDateTimeAxis;
          chart->addAxis(axisX, Qt::AlignBottom);
          series->attachAxis(axisX);
      
          QValueAxis *axisY = new QValueAxis;
          chart->addAxis(axisY, Qt::AlignLeft);
          series->attachAxis(axisY);
      

      Then, in some another place i'm replacing series:

      QLineSeries *series=(QLineSeries*)(view->chart()->series().first());
      QList<QPointF> list;
      
          for(int i=0;i<70000;i++)
          {
              list.append(QPointF(i,i-20));
          }
          series->replace(list);
      
      

      How can i update axis after this?

      1 Reply Last reply Reply Quote 0
      • B
        bronstein87 last edited by bronstein87

        there is no easy way to do it, so it can be done something like that:

        // create a pointer to old chart
            QChart* chartToDelete=NULL;
            if(view->chart())
            {
                chartToDelete=view->chart();
            }
            QChart* chart= new QChart();
            QLineSeries *series = new QLineSeries();
           // here you create Axis, attach them to series and so on
        
        
        
            view->setChart(chart);
            // here delete old chart
            delete chartToDelete;
        
        1 Reply Last reply Reply Quote 1
        • S
          SamGrant last edited by

          On the QML side, I do this just by changing the 'min' and 'max' values when updating the series.

          Doesn't that work on the C++ side as well:

          http://doc.qt.io/qt-5/qvalueaxis.html#max-prop
          http://doc.qt.io/qt-5/qvalueaxis.html#min-prop

          --Sam

          1 Reply Last reply Reply Quote 0
          • First post
            Last post