Qt 如何在QML中使用mousearea在图表视图中滚动

Qt 如何在QML中使用mousearea在图表视图中滚动,qt,qml,qquickview,Qt,Qml,Qquickview,我写了这段代码,我希望当鼠标滚轮以某种方式转动时,图表视图能够向右或向左滚动 ChartView { id: chartView animationOptions: ChartView.NoAnimation theme: ChartView.ChartThemeDark ValueAxis { ... } ValueAxis { ... } LineSeries { ...

我写了这段代码,我希望当鼠标滚轮以某种方式转动时,图表视图能够向右或向左滚动

ChartView {
    id: chartView
    animationOptions: ChartView.NoAnimation
    theme: ChartView.ChartThemeDark 
    ValueAxis {
        ...
    }
    ValueAxis {
        ...
    }
    LineSeries {
        ...
    }
    MouseArea {
        anchors.fill: parent

        onWheel: {
            if (wheel.modifiers & Qt.ControlModifier){
                if (wheel.angleDelta.y > 0)
                {
                    chartView.scrollRight(5)
                }
                else
                {
                    chartView.scrollLeft(5)
                }
                wheel.accepted=true
            }
            else{
                wheel.accepted=false
            }
        }
    }
}
但不起作用。
我缺少什么?

我会使用滚动视图:

Rectangle {
    width: 200 //size of the viewed part
    height: 200 //size of the viewed part
    color: "transparent"
    clip: true
    ScrollView {
        anchors.fill: parent
        contentWidth: chartRec.width
        contentHeight: chartRec.height
        Rectangle {
            id: chartRec
            height: 400 //size of the chart
            width: 400 //size of the chart 
            color: "transparent"
            ChartView {
                id: chartView
                anchors.fill: parent
                animationOptions: ChartView.NoAnimation
                theme: ChartView.ChartThemeDark 
                ValueAxis {
                    ...
                }
                ValueAxis {
                    ...
                }
                LineSeries {
                    ...
                }
            }
        }
    }
}

第二个矩形的大小应大于第一个矩形的大小。否则,将不显示滚动视图

scrollview可以让我看到绘制在图表视图边界之外的点(最小值:最大值)?