更新代码
This commit is contained in:
@@ -21,6 +21,7 @@ void frmSimple::initForm()
|
||||
ui->customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
|
||||
ui->customPlot->addGraph();
|
||||
ui->customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
|
||||
|
||||
// generate some points of data (y0 for first, y1 for second graph):
|
||||
QVector<double> x(251), y0(251), y1(251);
|
||||
for (int i = 0; i < 251; ++i) {
|
||||
@@ -28,15 +29,18 @@ void frmSimple::initForm()
|
||||
y0[i] = qExp(-i / 150.0) * qCos(i / 10.0); // exponentially decaying cosine
|
||||
y1[i] = qExp(-i / 150.0); // exponential envelope
|
||||
}
|
||||
|
||||
// configure right and top axis to show ticks but no labels:
|
||||
// (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
|
||||
ui->customPlot->xAxis2->setVisible(true);
|
||||
ui->customPlot->xAxis2->setTickLabels(false);
|
||||
ui->customPlot->yAxis2->setVisible(true);
|
||||
ui->customPlot->yAxis2->setTickLabels(false);
|
||||
|
||||
// make left and bottom axes always transfer their ranges to right and top axes:
|
||||
connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
|
||||
connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));
|
||||
|
||||
// pass data points to graphs:
|
||||
ui->customPlot->graph(0)->setData(x, y0);
|
||||
ui->customPlot->graph(1)->setData(x, y1);
|
||||
|
||||
Reference in New Issue
Block a user