Search code examples
qtqmlqtquick2qchart

QCharts Second Y Axis on the Right Side


I want to place a second ValueAxis on the right side of a ChartView. The documentation states that "The axes can be placed down, up, left, or right of the chart."

However I find no property in the documentation of AbstractAxis, ValueAxis or ChartView that accords to this. Only the alignment property of AbstractAxis drew my attention, however it is const and can not be modified in QML:

Invalid property assignment: "alignment" is a read-only property

I can see that there is a C++ way to set the alignment in the Multiple Axes Example, but I am looking for a QtQuick way to set the alignment. Am I missing something here?


Solution

  • Use appropriate properties of series instead of axis, for example:

    ValueAxis {
        id: axisX
    }
    ValueAxis {
        id: axisY
    }
    LineSeries { // axes are right-bottom
        axisX: axisX
        axisYRight: axisY
    }
    LineSeries { // axes are top-left
        axisXTop: axisX
        axisY: axisY
    }
    

    And yes, I agree that alignment is misleading and that would be clearer to set axis using this property.