Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to set Value Axis Label Format on QML from milliseconds to mm:ss?



  • Background

    I am using QtCreator and I have a file called myScopeView.qml, which represents a scope view similar to the example provided here.

    In myScopeView.qml, there is a ChartView that is updated every second with a timer so the plot changes values on X axis and Y axis.

    X axis represents time expressed in milliseconds (integer values), because of the data acquisition, and Y axis represents voltage values (characterized as integer values).

    Problem

    The plot shows X axis values as integer, i.e. 123456789, but I would like to visualize the corresponding mm:ss value, i.e. 20:34. I think I have to modify the value of labelFormat.

    ValueAxis{
        id: axisX
        min: 0
        max: 0
        tickCount: 5
        labelFormat: // I don't know what I have to set here
        }
    

    Question

    Is it possible to set a specific value in labelFormat in order to have mm:ss visualized?

    Notes

    Instead of the modification of labelFormat I tried to use a Javascript function for the conversion but this solution does not work because the conversion is achieved before the visualization and so the plot shows nothing because there is no Y values associated to new X values. That's why I am asking for a labelFormat command, but I will appreciate also a Javascript hint.

    I know that QML QtCharts has QDateTimeAxis which provides mm:ss format but I would like to convert data only for the visualization and not for other purposes.


Log in to reply