Hi!

I have a file with lots of data in it (for this example, 32 plots with several million points each). So to prevent long loading time, I want to just load the data that will be displayed on the graphs. If the user want to see the next page or change the scale of the plots, the new data are loaded.
I can display the graphs one below the other, and when changing the page, it works good (for example, the first page contain the points from 0 to 10000, the second from 10001 to 20000...).
But I have a problem when changing the scales, either on the x- or the y-axis.

Here's how I create my plots :

Qt Code:
  1. void CentralMiddleLayer::displayFirstLoading()
  2. {
  3. // Creation of the x axis
  4. //--------------------
  5. x.resize(scale);
  6. for (int i = 0; i < scale; i++)
  7. x[i] = i;
  8.  
  9. // Matrix dimensions resize
  10. //--------------------
  11. matrix.resize(channelNb); // First dimension
  12. for (int i = 0; i < channelNb; i ++)
  13. matrix[i].resize(scale); // Second dimension
  14.  
  15. // Get data from file, put into the matrix
  16. //--------------------
  17. FileReader::yAxisData(filename, matrix, actualRange.lower, scale); // This is the function that will read the file and put the data of interest in the matrix
  18.  
  19.  
  20.  
  21. plot = new QCustomPlot;
  22. nbGraph = 32;
  23.  
  24. // Offset the data so they're not on top of each other
  25. //----------------------------------------
  26. QCPRange defaultRange(-100., 100.); // y-axis range
  27. for (int i = 0; i < nbGraph; i++)
  28. {
  29. QCPAxis *axis = plot->axisRect()->addAxis(QCPAxis::atLeft);
  30. axis->setRange(defaultRange.lower - (nbGraph - 1 - i) * defaultRange.size(), defaultRange.upper + i * defaultRange.size()); // I don't really understand why this work to be honest...
  31. axis->setVisible(false);
  32.  
  33. QCPGraph *graph = new QCPGraph(plot->xAxis, axis);
  34. }
  35.  
  36.  
  37. // Set the data to the plot
  38. //----------------------------------------
  39. for(int i = 0; i < plot->graphCount(); i++)
  40. {
  41. plot->graph(i)->setData(x, matrix[i], true);
  42. }
  43.  
  44.  
  45. // Set plot characteristics
  46. //----------------------------------------
  47. plot->xAxis->setRange(0, 10000.0); // Number of point per page
  48.  
  49. plot->xAxis->setVisible(false);
  50. plot->yAxis->setVisible(false);
  51.  
  52. plot->axisRect()->setAutoMargins(QCP::msNone);
  53. plot->axisRect()->setMargins(QMargins(0, 10, 0, 0));
  54. plot->setStyleSheet(("background:hsva(255, 255, 255, 0%);"));
  55. plot->setBackground(QBrush(Qt::NoBrush));
  56.  
  57. plot->setFixedHeight(700);
  58. }
To copy to clipboard, switch view to plain text mode 


Now, I don't see how to change the scales.

For the x-axis (time scale), if I rescale it when the application is running (for example I want 15000 points per graph instead of 10000), I get this error message :
void QCPGraph::addData(const QVector<double>&, const QVector<double>&, bool) keys and values have different sizes: 10000 15000
Here's the code I use for this :

Qt Code:
  1. void CentralMiddleLayer::timeScaleChange(double time)
  2. {
  3. scale = time; // the new time scale = how many point displayed per page and per graph
  4.  
  5. for (int i = 0; i < channelNb; i ++)
  6. matrix[i].resize(scale); // the data matrix get its new size
  7.  
  8. setActualRange(actualRange.lower);
  9. FileReader::yAxisData(filename, matrix, actualRange.lower, actualRange.upper); // the new data are read, the data corresponding to the new range are put inside the matrix
  10.  
  11. for(int i = 0; i< plot->graphCount(); i++)
  12. plot->graph(i)->setData(x, matrix[i]); // the graphs receives their new data. From the documentation, this should work fine...
  13.  
  14. plot->xAxis->setRange(0, scale);
  15.  
  16. plot->replot();
  17. }
To copy to clipboard, switch view to plain text mode 

And for the y-axis, If I change the scale nothing happen...


If someone is used to QCustomPlot, do you have any advice ?
I think my problem comes from the way I construct my graph, but on important point that I can't ignore is that the graphs have to be able to overlap each other (if the datas requires it). And I only find this way to do it. Is there an other one ?