QML图表视图中的自定义工具提示

马森

我已经使用代码设置了自定义工具提示

ChartView {
    id: chart
    anchors.fill: parent
    antialiasing: true
    ValueAxis {
        id: axisY
        tickCount: 3
    }
    DateTimeAxis{
           id: xTime
           gridVisible: false
       }
    ToolTip {
        id: id_toolTip
        contentItem: Text{
            color: "#21be2b"
        }
        background: Rectangle {
                border.color: "#21be2b"
            }

    }
    SplineSeries{
        id: chartseries
        pointsVisible: true
        pointLabelsVisible: false
        useOpenGL: true
        axisX: xTime
        axisY: axisY
        onClicked: {
            id_toolTip.show("dd")
         }
    }

}

当我单击图形时它给出一个错误..

TypeError: Property 'show' of object QQuickToolTip(0x37275d0) is not a function" 

但是下面提到的代码将起作用。

  chart.ToolTip.show("dd")

但是我需要自定义工具提示

永乐

您可以使用其他属性,如下所示:

ChartView {
    id: chart
    anchors.fill: parent
    antialiasing: true
    ValueAxis {
        id: axisY
        tickCount: 3
        max: 4
        min: 0
    }
    DateTimeAxis{
        id: xTime
        gridVisible: false
    }

    ToolTip {
        id: id_tooltip
        contentItem: Text{
            color: "#21be2b"
            text: id_tooltip.text
        }
        background: Rectangle {
            border.color: "#21be2b"
        }
    }

    SplineSeries{
        id: chartseries
        XYPoint { x: new Date('December 17, 1995 03:24:00').getTime() ; y: 0.0 }
        XYPoint { x: new Date('December 18, 1995 04:25:00').getTime() ; y: 3.2 }
        XYPoint { x: new Date('December 19, 1995 05:26:00').getTime() ; y: 2.4 }
        XYPoint { x: new Date('December 20, 1995 06:27:00').getTime() ; y: 2.1 }
        XYPoint { x: new Date('December 21, 1995 07:24:00').getTime() ; y: 0.0 }
        XYPoint { x: new Date('December 22, 1995 08:25:00').getTime() ; y: 3.2 }
        XYPoint { x: new Date('December 23, 1995 09:26:00').getTime() ; y: 2.4 }
        XYPoint { x: new Date('December 24, 1995 10:27:00').getTime() ; y: 2.1 }

        pointsVisible: true
        pointLabelsVisible: false
        useOpenGL: true
        axisX: xTime
        axisY: axisY
        onClicked: {
            var p = chart.mapToPosition(point)
            var text = qsTr("x: %1, y: %2").arg(new Date(point.x).toLocaleDateString(Qt.locale("en_US"))).arg(point.y)
            id_tooltip.x = p.x
            id_tooltip.y = p.y - id_tooltip.height
            id_tooltip.text = text
            //id_tooltip.timeout = 1000
            id_tooltip.visible = true
        }
    }
}

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章