QCustomPlot Discussion and Comments

How to create/show tick labels at the right side of the graph?Return to overview

Hi!

I want to show a two graphs on the same plot - temperature with the labels at left side and pressure with the labels at right side.
I tried to create it like described in the multiaxisdemo article, but there is still no tick labels on the right side of the plot, no matter how hard I try it.

My code:

    m_customPlot->yAxis2->setVisible(true);

    m_customPlot->addGraph( m_customPlot->xAxis , m_customPlot->yAxis ); // red line - temperature graph(0)
    m_customPlot->graph(0)->setPen(QPen(QColor(255, 110, 40)));
    m_customPlot->yAxis->setRange( 0.0, 100.0 ); // temperature scale at left
    m_customPlot->yAxis->setLabel("Temperature");
    m_customPlot->graph(0)->setName( tr("Temperature") );

    m_customPlot->addGraph( m_customPlot->xAxis , m_customPlot->yAxis2 ); // blue line - pressure graph(1)
    m_customPlot->graph(1)->setPen(QPen(QColor(40, 110, 255)));
    m_customPlot->yAxis2->setRange(0.0, 4.0); // Pressure scale at right
    m_customPlot->yAxis2->setLabel("Pressure");
    m_customPlot->graph(1)->setName( tr("Pressure") );
    m_customPlot->yAxis2->setTickLength(m_customPlot->yAxis->tickLengthIn(), 0);
    m_customPlot->yAxis2->setSubTickLength(m_customPlot->yAxis->subTickLengthIn(), 0);
    m_customPlot->yAxis2->setVisible(true);
    m_customPlot->yAxis2->setTickLabels(true);
    m_customPlot->yAxis2->ticker()->setTickCount(4);
    m_customPlot->yAxis2->ticker()->setTickOrigin(0.0);
    
    QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
    timeTicker->setTimeFormat("%h:%m:%s");
    m_customPlot->xAxis->setTicker(timeTicker);
    m_customPlot->axisRect()->setupFullAxesBox();

Please, help me, what I am doing wrong?

Hi!

Also, on the first graph I set range 0-100 (for temperature) and on the second graph I set range 0-4 (in Bar units), but when I add points to second graph they are shown near zero - it seems like temperature scale is used to display theese both graphs.

How I can set different scales and axis labels for the two independent graphs on the same plot?