簡體   English   中英

為什么 QCustomPlot 在繪制大數據時速度太慢?

[英]Why QCustomPlot is too slow in ploting large data?

我想繪制每 100 毫秒出現的大量數據 (3k)。 我用精確的 3k 點嘗試了QCustomPlotQwt ,我在使用 Qwt 繪圖時獲得了非常好的性能,而使用 QCustomPlot 的性能非常差。 而且我認為我對 QCustomPlot 的行為有誤,我使用此代碼在 QCustomPlot 中繪圖(此示例來自 QCustomPlot plot-examples ,我編輯了函數setupQuadraticDemo ):

void  MainWindow::setupQuadraticDemo(QCustomPlot *customPlot)
{
 demoName = "Quadratic Demo";
 customPlot->addGraph();
 customPlot->setNotAntialiasedElements(QCP::AntialiasedElement::aeAll);

 customPlot->xAxis->setRange(0, 1000);
 customPlot->yAxis->setRange(0, 1000);

 customPlot->xAxis->setLabel("x");
 customPlot->yAxis->setLabel("y");

 connect(&dataTimer, &QTimer::timeout, this, [customPlot]
 {
  constexpr auto length = 3000;
  QVector<double> x(length), y(length);

  std::srand(std::time(nullptr));

  for (int i = 0; i < length; ++i)
  {
   x[i] = std::rand() % 1000;
   y[i] = std::rand() % 1000;
  }

  customPlot->graph(0)->setData(x, y, true);

  customPlot->replot();
 });

 dataTimer.start(100);
}

以及 Qwt 的這段代碼 QCustomPlot 是我做錯了嗎? 為什么繪圖太慢?

我想問題的根源在於代碼本身。 您以錯誤的方式更新積分。 您必須從代碼中刪除以下行

std::srand(std::time(nullptr));

此行將強制rand()的種子在確定的時間內固定(如果我想准確地說,您的種子值固定為1 second ),因此無論數據本身是否更新,您都看不到任何更改,因為重新繪圖將在該持續時間( 1 sec )內繪制相同的點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM