QCustomPlot Discussion and Comments

How to draw infinite Line on horizontally?Return to overview

I want to add 2 fixed lines horizontally of the chart. I tried the below Code but it adds the line vertically. How can I make it horizontal?


QCPItemStraightLine *infLine = new QCPItemStraightLine(customPlot);
infLine->point1->setCoords(2, 0);  // location of point 1 in plot coordinate
infLine->point2->setCoords(2, 1);  // location of point 2 in plot coordinate

You are providing two points that share the same x coordinate, thus the line is vertical. If you want an horizontal line, use two points that share the same y coordinate; for example:

QCPItemStraightLine *infLine = new QCPItemStraightLine(customPlot);
infLine->point1->setCoords(0, 2);  // location of point 1 in plot coordinate
infLine->point2->setCoords(1, 2);  // location of point 2 in plot coordinate