Skip to content

Axis formats

Axis values remain numeric. A formatter changes only the displayed tick text.

Date and time

Use milliseconds since the Unix epoch as X values and attach a QAccelPlot.DateTimeTickLabelFormatter:

xAxis: QAccelPlot.Axis {
    viewportMin: traceStart
    viewportMax: traceEnd

    ticker.tickLabelFormatter: QAccelPlot.DateTimeTickLabelFormatter {
        dateTimeFormat: "hh:mm:ss.zzz"
    }
}

Supply epoch values through setData(), which keeps double precision; the F APIs store floats.

Categories

Map integer coordinates to labels with QAccelPlot.TextTickLabelFormatter:

xAxis: QAccelPlot.Axis {
    viewportMin: 0
    viewportMax: 6
    ticker.tickCount: 6
    ticker.subtickCount: 0
    ticker.tickLabelFormatter: QAccelPlot.TextTickLabelFormatter {
        labels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
    }
}

The data points still use X coordinates 0 through 6. Zoomed in, the axis still ticks only at whole numbers, so each category is labeled once.

Logarithmic axes

Enable a base-10 logarithmic mapping:

xAxis: QAccelPlot.Axis {
    viewportMin: 20
    viewportMax: 20000
    logScale: true
}

Logarithmic ranges must stay positive. The default NumericTickLabelFormatter labels each decade tick as a power of ten, such as 10⁻³ and 10².

Application-specific labels

For custom text, assign a JavaScript function to a formatter's tickLabel property. It runs for every tick label, so keep it cheap:

yAxis: QAccelPlot.Axis {
    viewportMin: 18
    viewportMax: 26
    label: "Temperature"

    ticker.tickLabelFormatter: QAccelPlot.NumericTickLabelFormatter {
        tickLabel: function (temperature) {
            return temperature.toFixed(1) + " °C"
        }
    }
}

Complete source: examples/axes/tick_formats