title: Graphing issues in data output
body: <p>I have a program that is taking input from an external source (right now, a joystick), and then plotting it on a graph.  The graph displays the last 60 frames of data, which is about 1-2 seconds.</p>
  
  <p>here is the data input:</p>
  
  <pre><code>nextDataPoint(double x){
      if (x &gt; max){ max = x; }
      if (x &lt; min){ min = x; }
      dataInput.enqueue(x) //dataInput is a QQueue&lt;double&gt;
      while (dataInput.size() &gt; 60){
          dataInput.dequeue();
      }
      update(); //this triggers the paint event
  }
  </code></pre>
  
  <p>here is the graphing function</p>
  
  <pre><code>graph function:
  
  //this draws the min line and the max line
  QPainter painter(this);
  int lineDist = 25;
  QPen myPen(Qt::black, 3);
  QPoint maxText(10,20);
  painter.drawText(maxText, "max");
  QPoint maxLineLeft(0, lineDist);
  QPoint maxLineRight(width(), lineDist);
  painter.drawLine(maxLineLeft, maxLineRight);
  QPoint minText(10, height()-10);
  painter.drawText(minText, "min");
  QPoint minLineLeft(0, height()-lineDist);
  QPoint minLineRight(width(), height()-lineDist);
  
  //this draws the actual graph
  myPen.setColor(Qt::blue);
  myPen.setWidth(2);
  painter.setPen(myPen);
  double dist = (double)(heigh() - 2*lineDist);
  int stepSize = (int)((double)width() / 60.0);
  int heightStep = (max-min)/dist;
  double x;
  QPoint lastPoint(0,0);
  QPoint nextPoint(0,0);
  int i = 0;
  if (!dataInput.empty()){ //checks that there is data
      if (dataInput.size() &lt; 60) { //ignoring for sake of brevety
      } else {
          x = dataInput.at(i);
          x = max - x; // this inverts the data, necessary because (0,0) is the upper left corner
          x = (x-min)/heightStep;
          nextPoint.setX(0);
          nextPoint.setY(x+lineDist);
          for (i = 1; i &lt; 60; i++){
              x = dataInput.at(i);
              x = max - x;
              x = (x-min)/heightStep;
              lastPoint = nextPoint;
              nextPoint.setX(i*stepSize);
              nextPoint.setY(x+lineDist);
              painter.drawLine(lastPoint, nextPoint);
          }
      }
  }
  </code></pre>
  
  <p>So, with one joystick that I am testing with, this program works without issue.  As I move the joystick, the program draws the blue line within the bounds listed on the screen.  x is input as a number between 0 and 65535, and after moving the joystick around a little bit the system recognizes that as the max and the min, and then proceeds to function as expected.</p>
  
  <p>The second "joystick" is less of a joystick and more of a pressure sensor.  This outputs either x = 1023 or x is some number between 5 and 9.  In this case however, the blue line appears on the same level as the max line, or when the data output is x in the single digits, the blue line appears below min.  I haven't been able to figure out why this would be the case, the first joystick can also produce results of 0, but it never goes below the minimum line.  What might be causing this particular issue?</p>