ChartView: Dynamically creating a series with a right axis (at a different scaling)



  • I'm trying to generate a chart every second line of which is referenced to an y axis on the right.

    I have a ChartView with multiple axis created inside:

        ChartView {
            id: uiChart
            anchors.fill: parent
    
            // @disable-check M17
            legend.visible: false
    
            antialiasing: true
            animationOptions: ChartView.NoAnimation
    
            ValueAxis {
                id: xaxisI
    
                minorTickCount: 4
                tickCount: 5
    
                titleText: "I / µA"
            }
    
            ValueAxis {
                id: yaxisU
    
                minorTickCount: 4
                tickCount: 5
    
                titleText: "U / µV"
            }
    
            ValueAxis {
                id: yaxisR
    
                gridVisible: false
                minorTickCount: yaxisU.minorTickCount
                tickCount: yaxisU.tickCount
           }    
    

    The limits for the axes are set dynamically. Now I want to generate two series, one against yaxisU on the left, other agains yaxisR on the right:

    var uSeries = uiChart.createSeries(ChartView.SeriesTypeLine, a, xaxisI, yaxisU)
    var rSeries = uiChart.createSeries(ChartView.SeriesTypeLine, a, xaxisI, yaxisR)
    

    If I do it like so, it does work, but both axis apear near each other to the left of the chart. If I try to set rSeries.axisYRight = yaxisR later, it doesn't change anything. On the other hand, if I try to omit yaxisR in the createSeries call and only set it later via rSeries.axisYRight, the R axis does appear on the right but the uSeries appears scaled to yaxisR rather then yaxisU.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.