QCustomPlot Discussion and Comments

Zoom on multiple axesReturn to overview

Hi,

I have implemented multiple axes with customplot, but I am unable to zoom the axis (y2,y3,y4 etc..). Is there any solution/suggestion for this problem.

Thank you!

Is there anyone who is going to help with this...

isnt zooming just calling 'setRange' on the axis? i'm unsure as to what you mean by you cant zoom the axis.

Thanks for responding.
I have plotted graphs by having multiple axis(I have 4 plots with each plot having a different y axis and same x axis) as mentioned in advanced axes demo and everything is working properly. But when I tried to zoom or drag the axes only one plot is getting zoomed and able to drag. How to change this behavior?

Thanks in advance

See documentation:
setRangeDragAxes and setRangeZoomAxes

Thanks for the suggestion even though I couldn't able to fix the issue . Here is a piece of code that I wrote. Please have a look.

multiAxisRect = new QCPAxisRect(ui->customPlot);
ui->customPlot->plotLayout()->addElement(1,0,multiAxisRect);

QCPMarginGroup *marginGroup = new QCPMarginGroup(ui->customPlot);
multiAxisRect->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);

if (graphCount>0)
{
multiAxisRect->addAxis(QCPAxis::atLeft);
multiAxisRect->axis(QCPAxis::atLeft,graphCount)->setVisible(true);
}
else
multiAxisRect->axis(QCPAxis::atLeft,0)->setVisible(true);

QCPGraph *graph = ui->customPlot->addGraph(multiAxisRect->axis(QCPAxis::atBottom),multiAxisRect->axis(QCPAxis::atLeft,graphCount));
graph->setData(x,y);
graph->setName(parameter);
graph->rescaleValueAxis();
graphCount++;

// To add legends to the sublayouts
QCPLegend *legend = new QCPLegend;
multiAxisRect->insetLayout()->addElement(legend, Qt::AlignTop|Qt::AlignRight);
ui->customPlot->setAutoAddPlottableToLegend(false);

if(graphCount==1)
graph->setPen(QPen(Qt::blue));
else if(graphCount==2)
graph->setPen(QPen(Qt::red));
else if(graphCount==3)
graph->setPen(QPen(Qt::magenta));
else if(graphCount==4)
graph->setPen(QPen(Qt::black));
else if(graphCount==5)
graph->setPen(QPen(Qt::green));
else
graph->setPen(QPen(Qt::darkCyan));

ui->customPlot->update();
ui->customPlot->legend->setVisible(true);

legend->setFont(QFont("Helvetica",9));
legend->addItem(new QCPPlottableLegendItem(legend,graph));

if(graphCount>0)
{
if(graphCount==1)
delete ui->customPlot->axisRect(0);
else
delete ui->customPlot->axisRect(graphCount);

ui->customPlot->plotLayout()->simplify();
}

foreach (QCPAxisRect *rect, ui->customPlot->axisRects())
{
rect->setRangeDragAxes(ui->customPlot->xAxis,ui->customPlot->yAxis);
rect->setRangeZoomAxes(ui->customPlot->xAxis,ui->customPlot->yAxis);
foreach (QCPAxis *axis, rect->axes())
{
axis->setLayer("axes");
axis->grid()->setLayer("grid");
axis->rescale(true);
}
}

foreach(QCPAxisRect *rect, ui->customPlot->axisRects())
{
foreach(QCPGraph *graph, rect->graphs())
{
graph->rescaleKeyAxis();
graph->setSelectable(QCP::SelectionType(true));
}
}

ui->customPlot->setInteraction(QCP::iRangeDrag,true);
ui->customPlot->setInteraction(QCP::iRangeZoom,true);

ui->customPlot->replot();

My problem is similar to the following post::

https://www.qcustomplot.com/index.php/support/forum/422

Do i have to implement manually as mentioned in the following thread

https://www.qcustomplot.com/index.php/support/forum/975