Reputation: 663
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
Upvotes: 3
Views: 1989
Reputation: 3996
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);
Upvotes: 3