简体   繁体   中英

QCustomPlot fills in lines that connect

Using the QCustomPlot add on for QT. I am having to plot points which may are not linear so the graph could look something like this在此处输入图片说明

how ever this is the result

在此处输入图片说明

but this is what shows up

using this code

    plotter->addGraph();
    plotter->graph(0)->setData(xVector, yVector);
    plotter->xAxis->setLabel("X");
    plotter->yAxis->setLabel("Y");
    plotter->xAxis->setRange(x_data_range_min x_data_range_max);
    plotter->yAxis->setRange(y_data_range_min, y_data_range_max);
    plotter->replot();
    plotter->saveJpg("test.jpg");
    plotter->close();

now I found a partial fix, by adding this option to get ride of the connected lines and only show the points,

    plotter->graph(0)->setLineStyle((QCPGraph::LineStyle)QCPGraph::lsNone);
    plotter->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc , 3));

and the result is this but has a problem, it leaves a kinda bold spot which I can't have

在此处输入图片说明

so this is a semi-solution. So I went ahead and added what A. Sarid mentioned in the replys below. I think the first graph may plot fine, but any other graph after it looks like this

在此处输入图片说明

so I am not sure which solution can make only the dots connect in the order in which they are received from the array

I just had the same problem few days ago. You need to use QCPCurve Class instead of Graph. Here is a small example of how to do it:

this->newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
ui->customPlot->addPlottable(this->newCurve);

And then you can use it the same way you use graph, for example:

this->newCurve->setData(x, y);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM