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. QChart : Update\rescale axis after series update

QChart : Update\rescale axis after series update

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 7.4k 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.
  • B Offline
    B Offline
    bronstein87
    wrote on last edited by bronstein87
    #1

    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
    0
    • B Offline
      B Offline
      bronstein87
      wrote on last edited by bronstein87
      #2

      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
      1
      • S Offline
        S Offline
        SamGrant
        wrote on last edited by
        #3

        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
        0

        • Login

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