-2

Qt の QCustomPlot で複数の sin を描きたいです。罪が互いに怒鳴り合いたい。実際には、心電図のようなものを見せたいです。誰でも私を助けることができますか?

4

1 に答える 1

2

あなたの要件は非常に短いので、簡単な解決策を示します。

複数の正弦波グラフを customPlot オブジェクトに追加し、各正弦波にオフセットを追加するだけです。

  customPlot->addGraph();
  customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
  customPlot->addGraph();
  customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
  customPlot->addGraph();
  customPlot->graph(2)->setPen(QPen(Qt::green)); // line color green for third graph
  customPlot->addGraph();
  customPlot->graph(3)->setPen(QPen(Qt::yellow)); // line color yellow for fourth graph
  // generate some points of data
  QVector<double> x(250), y0(250), y1(250), y2(250), y3(250);
  for (int i=0; i<250; ++i)
  {
    x[i] = i;
    y0[i] = qCos(i/10.0);
    y1[i] = qCos(i/10.0) + 3;   //add offset
    y2[i] = qCos(i/10.0) + 6;   //add offset
    y3[i] = qCos(i/10.0) + 9;   //add offset
  }
  // configure right and top axis to show ticks but no labels:
  // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
  customPlot->yAxis->setTickLabels(false);
  customPlot->xAxis2->setVisible(true);
  customPlot->xAxis2->setTickLabels(false);
  customPlot->yAxis2->setVisible(true);
  customPlot->yAxis2->setTickLabels(false);
  // make left and bottom axes always transfer their ranges to right and top axes:
  connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
  // pass data points to graphs:
  customPlot->graph(0)->setData(x, y0);
  customPlot->graph(1)->setData(x, y1);
  customPlot->graph(2)->setData(x, y2);
  customPlot->graph(3)->setData(x, y3);
  // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
  customPlot->graph(0)->rescaleAxes();
  // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
  customPlot->graph(1)->rescaleAxes(true);
  customPlot->graph(2)->rescaleAxes(true);
  customPlot->graph(3)->rescaleAxes(true);
  // Note: we could have also just called customPlot->rescaleAxes(); instead
  // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
  customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

結果は次のようになります。 ここに画像の説明を入力

于 2015-09-17T10:32:16.120 に答える