title: QTCharts, how do I make the chart follow the x-axis as live data comes in?
body: <p>I'm attempting to make a chart that reads in data live. I started from the example Qt provides called "dynamic spline".</p>
  
  <p>The issue I'm having is, the scroll() function appears to scroll pixels and there doesn't appear to be any function in Qt that I can find that scrolls along with the data. So unless I get the pixes scroll count exactly right, either my plot line grows until the end is no longer visible, or the chart scrolls on by leaving the plot line behind.</p>
  
  <p>This to me seams like a rather obvious feature everyone would use with a dynamic chart, so I'm left asking the question: what feature in Qt charts am I missing that does this?</p>
  
  <p>All my searching has been in vain, I haven't even been able to find a tutorial on how to use dynamic data collection in Qt charts.</p>
  
  <pre><code>#include "chart.h"
  #include &lt;QtCharts/QAbstractAxis&gt;
  #include &lt;QtCharts/QSplineSeries&gt;
  #include &lt;QtCharts/QValueAxis&gt;
  #include &lt;QtCore/QTime&gt;
  #include &lt;QtCore/QDebug&gt;
  
  Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
      QChart(QChart::ChartTypeCartesian, parent, wFlags),
      m_series(0),
      m_axis(new QValueAxis),
      m_step(0),
      m_x(10),
      m_y(1)
  {
      qsrand((uint) QTime::currentTime().msec());
  
      QObject::connect(&amp;m_timer, SIGNAL(timeout()), this, SLOT(drawChart()));
      m_timer.setInterval(1000);
  
      m_series = new QSplineSeries(this);
      QPen green(Qt::red);
      green.setWidth(3);
      m_series-&gt;setPen(green);
      m_series-&gt;append(m_x, m_y);
  
      addSeries(m_series);
      createDefaultAxes();
      setAxisX(m_axis, m_series);
  //    m_axis-&gt;setTickCount(11);
      axisX()-&gt;setRange(0, 100);
      axisY()-&gt;setRange(-5, 10);
  
      m_timer.start();
      elapsedTime.start();
  }
  
  Chart::~Chart()
  {
  
  }
  
  void Chart::drawLine(qreal &amp;x, qreal &amp;y)
  {
      m_series-&gt;append(x, y);
  }
  
  qreal Chart::getTime()
  {
      return elapsedTime.elapsed() / 100;
  }
  
  void Chart::drawChart()
  {
      qreal x = plotArea().width() / m_axis-&gt;tickCount();
      qreal y = (m_axis-&gt;max() - m_axis-&gt;min()) / m_axis-&gt;tickCount();
      m_x = getTime();
      m_y = qrand() % 5 - 2.5;
      drawLine(m_x, m_y);
      scroll(x, 0);
  
      qDebug() &lt;&lt; getTime();
  }
  </code></pre>
  
  <p>The code is pretty simple, right now it's plotting but the line and the scroll are totally out of sink. And since I want to use time as my X-axis, and can't use the nice unscalable way the example was setup with.</p>
  
  <p>Right now the it's just plotting a random number. I'm not going to bother feeding it actual data until I get this scrolling thing sorted.</p>
  
  <p>Thanks in advance for the help. And if you know of some good tutorials on Qt charts, I would greatly appreciate it. Qt tutorials, good ones anyway, are extremely hard to find.</p>