Hi all,

I have this code to plot the x^2 curve:

Qt Code:
  1. // add curves
  2. QwtPlotCurve *curve1 = new QwtPlotCurve("Graph 1");
  3.  
  4. //set curve color
  5. curve1->setPen(QPen(Qt::red, 2));
  6.  
  7. // add curves
  8. curve1->attach(ui->qwtPlotWidget);
  9.  
  10. const int MAX_VALUES = 100;
  11. double x[2*MAX_VALUES], y1[2*MAX_VALUES];// x and y values
  12. for (int i (-MAX_VALUES); i < MAX_VALUES; i++)
  13. {
  14. x[i] = i;
  15. y1[i] = i*i;
  16. }
  17.  
  18. // copy the data into the curves
  19. curve1->setSamples(x, y1, 2*MAX_VALUES);
  20.  
  21. // finally, refresh the plot
  22. ui->qwtPlotWidget->replot();
To copy to clipboard, switch view to plain text mode 

But I get this strange plot:


What's wrong?

Regards.