-2

我想在 Qt 中使用 QCustomPlot 绘制多个罪孽。我希望罪恶互相咆哮。实际上,我想展示像 ECG 这样的东西。谁能帮我?

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 回答