Menu

#389 Why does the curve behave this way when using NaN values?

None
closed
None
5
2026-02-02
2026-01-30
Anonymous
No

Could you please take a look at what the issue might be? I'd really appreciate it!
I'm using Qt 5.15.8 and Qt 5.15.2, Debian 12, and qwt 6.3 (qwt was compiled only with QwtDll and QwtPlot).
Whether I use static data or dynamic data for testing, this issue persists.
Here's the code I used to create the QWt curve chart:

void CustomPlotPage::SetupPlot()
{
    plot_ = new QwtPlot(this);

    QFrame* canvasFrame = qobject_cast<QFrame*>(plot_->canvas());
    if (canvasFrame) {
        canvasFrame->setFrameStyle(QFrame::Box | QFrame::Raised);
        canvasFrame->setLineWidth(1);
    }
    plot_->canvas()->setPalette(QPalette(QColor(255, 255, 255)));
    plot_->canvas()->setAutoFillBackground(true);

    plot_->setAutoReplot(false);
    plot_->setCanvasBackground(QColor(255, 255, 255));

    for (int axisId : { QwtPlot::xBottom, QwtPlot::yLeft }) {
        QwtScaleWidget* scaleWidget = plot_->axisWidget(axisId);
        if (scaleWidget) {
            scaleWidget->setMargin(2);
            QFont scaleFont = scaleWidget->font();
            scaleFont.setPointSize(9);
            scaleWidget->setFont(scaleFont);
        }
    }

    plot_->setAxisTitle(QwtPlot::xBottom, tr("Time"));
    plot_->setAxisTitle(QwtPlot::yLeft, tr("Value"));

    int fontPixelSize = 16.0 / 669 * this->height();
    QFont font(this->font());
    font.setPixelSize(fontPixelSize);
    font.setBold(true);

    QwtText xAxisTitle = plot_->axisTitle(QwtPlot::xBottom);
    xAxisTitle.setFont(font);
    plot_->setAxisTitle(QwtPlot::xBottom, xAxisTitle);

    QwtText yLeftTitle = plot_->axisTitle(QwtPlot::yLeft);
    yLeftTitle.setFont(font);
    plot_->setAxisTitle(QwtPlot::yLeft, yLeftTitle);

    fontPixelSize = 14.0 / 669 * this->height();
    font.setPixelSize(fontPixelSize);
    font.setBold(false);
    plot_->setAxisFont(QwtPlot::xBottom, font);
    plot_->setAxisFont(QwtPlot::yLeft, font);

    plot_->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());

    grid_ = new QwtPlotGrid();
    grid_->attach(plot_);
    grid_->setMajorPen(QPen(Qt::gray, 0.5, Qt::DashLine));
    grid_->setMinorPen(QPen(Qt::lightGray, 0.3, Qt::DotLine));
    grid_->enableXMin(true);
    grid_->enableYMin(true);

    const QList<QColor> graphColor = {
        QColor("#E84855"), QColor("#2E86AB"), QColor("#40916C"),
        QColor("#F6AE2D"), QColor("#926AA6"), QColor("#F26419"),
        QColor("#00A8E8"), QColor("#8AC926"), QColor("#D81159"),
        QColor("#4CC9F0"), QColor("#FFB703"), QColor("#5E548E"),
        QColor("#FB8500"), QColor("#1B4332"), QColor("#0077B6"),
        QColor("#B5179E"), QColor("#94D2BD"), QColor("#BC4749"),
        QColor("#2A9D8F"), QColor("#8D99AE")
    };
    for (int i = 0; i < curveNames_.size(); ++i) {
        QColor color = graphColor[i % graphColor.size()];
        QwtPlotCurve *curve = new QwtPlotCurve(curveNames_.at(i));
        curve->setPen(color, 2.0);
        curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true);
        curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
        curve->setYAxis(QwtPlot::yLeft);
        curve->setData(seriesDatas_.at(i));
        curve->setBrush(Qt::NoBrush);
        curve->setCurveAttribute(QwtPlotCurve::Fitted, false);
        curve->attach(plot_);
    }

    panner_ = new QwtPlotPanner(plot_->canvas());
    panner_->setMouseButton(Qt::LeftButton);

    magnifier_ = new QwtPlotMagnifier(plot_->canvas());
    magnifier_->setMouseButton(Qt::NoButton);
    magnifier_->setWheelFactor(1.1);

    picker_ = new CustomPlotPicker(plot_, dataPairs_, curveNames_);

    CustomLegend* legend = new CustomLegend();
    legend->setDefaultItemMode(QwtLegendData::Clickable);
    legend->setStyleSheet("QwtLegendLabel {"
                          "   padding: 3px 10px;"
                          "   margin: 2px;"
                          "}");

    legend->setFrameStyle(QFrame::NoFrame);
    legend->setLineWidth(0);
    legend->setMidLineWidth(0);
    font.setPixelSize(fontPixelSize);
    font.setBold(false);
    legend->setFont(font);

    plot_->insertLegend(legend, QwtPlot::TopLegend);

    connect(legend, &QwtLegend::clicked, this, &CustomPlotPage::OnLegendClicked);

    plot_->canvas()->installEventFilter(this);

    cursorMarker_ = new QwtPlotMarker();
    cursorMarker_->setLineStyle(QwtPlotMarker::VLine);
    QPen pen(Qt::black, 1, Qt::DashLine);
    cursorMarker_->setLinePen(pen);
    cursorMarker_->attach(plot_);

    cursorMarker_->hide();

    QwtScaleWidget *xAxis = plot_->axisWidget(QwtPlot::xBottom);
    connect(xAxis, &QwtScaleWidget::scaleDivChanged, this, &CustomPlotPage::OnXAxisScaleChanged);
}
1 Attachments

Discussion

  • Uwe Rathmann

    Uwe Rathmann - 2026-02-01

    Using NaN values to split a curve into segments is not implemened. You have to use one curve per segment or overload drawCurve/drawSeries where you do the segments

     
    • Anonymous

      Anonymous - 2026-02-02

      Thank you very much for your help. The issue has been resolved.

       
  • Uwe Rathmann

    Uwe Rathmann - 2026-02-02
    • status: open --> closed
    • Group: -->
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB