Important: Please read the Qt Code of Conduct -

Auto Axes in QML Lineseries Charts

  • Hi

    In line series charts, i was append the c++ data to qml. Herewith add coding for your reference. In that i need to auto adjust the X and Y axes minimum and maximum value based on the received data from c++.

    ChartView {
        id: chartView
        title: "Real Time Charts"
        anchors.fill: parent
        animationOptions: ChartView.SeriesAnimations
        antialiasing: true
        theme: ChartView.ChartThemeBlueCerulean
        ValueAxis {
            id: axisY2
            min: 0
            max: 100
            minorTickCount: 3
            tickCount: 10
        ValueAxis {
            id: axisX
            min: 0
            max: 50
            minorTickCount: 3
            tickCount: 7
            gridVisible: false
           color: "white"
        LineSeries {
            id: lineSeries1
            name: "signal 1"
            axisX: axisX
            axisY: axisY1

    For rate changed, i was append the data to the lineseries...

            onRateChanged:  {




    Instead of defining X and Y min and max values, i need a solution to adjust min and max values automatically based on the received data.

  • I did something similar to this, but using JavaScript to read my data...

    I have two properties in my main.qml that are my min & max for my axis. I update them via the JavaScript.

    In my QML with the charts, I make sure that the min & max parameters point to the properties in my main.qml.

    main.qml :

    property alias appWin: mainWindow
    property double maxWspd: 0.0
    property double minWspd: 100.0


    if( appWin.maxWspd < Math.ceil((appWin.wxWspd))+1 ) {
        appWin.maxWspd = Math.ceil((appWin.wxWspd))+1;
    if( appWin.minWspd > Math.floor((appWin.wxWspd))-1 ) {
        appWin.minWspd = Math.floor((appWin.wxWspd))-1;


            ValueAxis {
                id: axisYw
                min: appWin.minWspd
                max: appWin.maxWspd
                tickCount: 5
                labelFormat: "%.1f"
                labelsFont:Qt.font({pointSize: 12})
                labelsColor: appWin.baseFontColor
                color: appWin.graphTickColor

Log in to reply