I want to plot a polygon graph based on the coordinates I input. However, after using setData(x, y) to add the data, the final graph is connected according to the x-axis coordinates, rather than the order in which I input the coordinates.
#include <QApplication> #include <QMainWindow> #include "qcustomplot.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow window; QCustomPlot *customPlot = new QCustomPlot(); QVector<double> x(17), y(17); x[0] = 0.86; y[0] = 0.15; x[1] = 0.73; y[1] = 0.56; x[2] = 0.43; y[2] = 0.86; x[3] = 0.11; y[3] = 1.01; x[4] = -0.25; y[4] = 1.00; x[5] = -0.56; y[5] = 0.87; x[6] = -0.79; y[6] = 0.58; x[7] = -0.92; y[7] = 0.21; x[8] = -0.89; y[8] = -0.21; x[9] = -0.72; y[9] = -0.62; x[10] = -0.44; y[10] = -0.92; x[11] = -0.16; y[11] = -1.04; x[12] = 0.16; y[12] = -1.08; x[13] = 0.52; y[13] = -0.91; x[14] = 0.74; y[14] = -0.75; x[15] = 0.89; y[15] = -0.30; customPlot->addGraph(); customPlot->graph(0)->setData(x, y); customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); customPlot->xAxis->setRange(-1.5, 1.5); customPlot->yAxis->setRange(-1.5, 1.5); customPlot->plotLayout()->insertRow(0); QCPTextElement *title = new QCPTextElement(customPlot, "XY Polygon", QFont("sans", 12, QFont::Bold)); customPlot->plotLayout()->addElement(0, 0, title); window.setCentralWidget(customPlot); window.resize(800, 600); window.show(); return a.exec(); }