QCustomPlot Discussion and Comments

Custom number formatting for axisReturn to overview

Hi

Do you know how I can display axis with a custom number formatting? Let say I have an axis with integers like (0, 1, 2, 3, 4, 5, ...), how can I have it displayed as ($0, $1, $2, $3, $4, $5, ...) or (0%, 1%, 2%, 3%, 4%, 5%, ...)?

I looked at setNumberFormat(), setNumberPrecision(), and at the QCPAxisTicker subclasses (QCPAxisTickerFixed, QCPAxisTickerLog, QCPAxisTickerPi, QCPAxisTickerText, QCPAxisTickerDateTime, QCPAxisTickerTime) but can't make it work...

Many thanks!

In your case you can just use QCPAxisTickerPi with the setPiValue to 1 and setPiSymbol to "%" or "$" for example.

If you want more flexibility, simply subclass QCPAxisTicker. How this works is explained in the detailed section of its documentation. In your case you probably only want to reimplement a single method: QCPAxisTicker::getTickLabel
(just call the base class getTickLabel, and prefix/suffix a string as needed).