QCustomPlot Discussion and Comments

How to label names fixed?Return to overview


I am working on a project that is similar to an oscilloscope. I get data from serial port. Next, I plot these values. My plot uses sample number as x axis, and each sample's value as y axis. However, there is a problem. It is better to show x axis' labels as 0, 1 .... 10 fixed numbers rather than each sample number that reaches thousands.. Is there a way to just rename labels?

Best wishes,

i think you want to look into QCPAxisTickerFixed

Hello, Ian

I checked that class reference, however I couldn't find any function to utilise. If I expressed my question properly, could you give me an idea to fix my issue? I would be appreciated.

Sorry for my English.


Do you have an idea of how you want to spread out those 1-10 across the area? what happens if you zoom in/out?

If you want it to work with zoom in/out and you want it to use 1-10 instead of 1-n, you may want to just scale the numbers going into the x axis so that it goes from 1-10. Using the QCPAxisTickerFixed , you would set the tick step to 1, then set your axis to use that ticker and then it would only show 1-10.

After read your reply. I checked the library again. I actually achieved what I would like to do. I've written the code given below.

Thank you for your replies,

void MainWindow::DoDefaultGraphConfigurations()
    QCPAxis *bottomAxis = ui->customPlot->axisRect()->addAxis(QCPAxis::atBottom);
    QSharedPointer<QCPAxisTickerFixed> bottomFixedTicker(new QCPAxisTickerFixed);
    bottomAxis->setRange(0, 10);