QCustomPlot Discussion and Comments

Plot line through multi axis plotReturn to overview

Hi. I am trying to make a line in a multi axis plot. I made a window that look like this: http://www.imagebam.com/image/d7bfa5326590446.
Here is part of the code to see how i made this.

	customPlot->plotLayout()->clear();
        customPlot->plotLayout()->setRowSpacing(-25);

        axis1 = new QCPAxisRect(customPlot);		//axis1 is private var
        customPlot->plotLayout()->addElement(0,0,axis1);
        axis1->axis(QCPAxis::atBottom)->setAutoTickLabels(false);

        QCPAxisRect *axis2 = new QCPAxisRect(customPlot);
        customPlot->plotLayout()->addElement(1,0,axis2);
        axis2->axis(QCPAxis::atBottom)->setAutoTickLabels(false);

        QCPAxisRect *axis3 = new QCPAxisRect(customPlot);
        customPlot->plotLayout()->addElement(2,0,axis3);
        axis3->axis(QCPAxis::atBottom)->setAutoTickLabels(false);



        QCPAxisRect *axis4 = new QCPAxisRect(customPlot);
        customPlot->plotLayout()->addElement(3,0,axis4);

        QCPGraph *Graph1 = customPlot->addGraph(axis1->axis(QCPAxis::atBottom), axis1->axis(QCPAxis::atLeft));
        Graph1->setData(x, y1);
        Graph1->

        QCPGraph *Graph2 = customPlot->addGraph(axis2->axis(QCPAxis::atBottom), axis2->axis(QCPAxis::atLeft));
        Graph2->setData(x, y2);

        QCPGraph *Graph3 = customPlot->addGraph(axis3->axis(QCPAxis::atBottom), axis3->axis(QCPAxis::atLeft));
        Graph3->setData(x, y3);

        QCPGraph *Graph4 = customPlot->addGraph(axis4->axis(QCPAxis::atBottom), axis4->axis(QCPAxis::atLeft));
        Graph4->setData(x, y4);

So i try to make a vertical line through this four graphs following this thread: http://www.qcustomplot.com/index.php/support/forum/110

Here is the code i write to make this line

void MainWindow::mousePress(QMouseEvent* event)
{

    QCustomPlot *customPlot=ui->custom;
    static QCPItemLine  *vCursor;

    double x = axis1->axis(QCPAxis::atBottom)->pixelToCoord(event->pos().x());

    vCursor = new QCPItemLine(customPlot);
    customPlot->addItem(vCursor);
    vCursor->start->setCoords( x, QCPRange::minRange);
    vCursor->end->setCoords( x, QCPRange::maxRange);

    customPlot->replot();
}

But in the application output i obtain "virtual QPointF QCPItemPosition::pixelPoint() const No axes defined"

Can any one help me. I only want to graph a vertical line through this four graphs.
Thanks.

Here is the solution

    QCustomPlot *customPlot=ui->custom;

    static QCPItemLine  *vCursor1, *vCursor2;

    double x = axis1->axis(QCPAxis::atBottom)->pixelToCoord(event->pos().x());
    double x2 = axis2->axis(QCPAxis::atBottom)->pixelToCoord(event->pos().x());



/*
    if(vCursor2) customPlot->removeItem(vCursor2);
    vCursor2 = new QCPItemLine(customPlot);
    customPlot->addItem(vCursor2);
    vCursor2->setClipToAxisRect(false);
    vCursor2->setClipAxisRect(axis2);
    vCursor2->start->setAxes(axis2->axis(QCPAxis::atBottom),axis2->axis(QCPAxis::atLeft));
    vCursor2->end->setAxes(axis2->axis(QCPAxis::atBottom),axis2->axis(QCPAxis::atLeft));
    vCursor2->start->setCoords( x2, QCPRange::minRange);
    vCursor2->end->setCoords( x2, QCPRange::maxRange);
*/
    if(vCursor1) customPlot->removeItem(vCursor1);
    vCursor1 = new QCPItemLine(customPlot);
    customPlot->addItem(vCursor1);
    vCursor1->setClipToAxisRect(false);
    vCursor1->setClipAxisRect(axis1);
    vCursor1->start->setAxes(axis1->axis(QCPAxis::atBottom),axis1->axis(QCPAxis::atLeft));
    vCursor1->end->setAxes(axis1->axis(QCPAxis::atBottom),axis1->axis(QCPAxis::atLeft));
    vCursor1->start->setCoords( x, QCPRange::minRange);
    vCursor1->end->setCoords( x, QCPRange::maxRange);





    customPlot->replot();