Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Touch in QML chartview



  • I have created a QML chart with code

         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.text = "dd"
                id_toolTip.visible = true;
             }
        }
    
    } 
    

    But tooltip is not showing on all touches . Sometimes it shows . Sometimes it did not. What will be the cause



  • @Refi
    That is probably due to the hotspot of the touch not being exactly on the graph sometimes...

    One obvious way to improve this is to increase the width of your graph lines, but that may not be too pretty.

    Another way is to determine the closest point on your graph using some code computations.

    My idiot's solutions is this: superimpose the same series, make its color "transparent" but give it a sufficiently wide line thickness and put the click handler there...



  • @Diracsbracket
    I think this is a good Idea . Will try this.
    Is there any to put tooltips only on graph points after making

    pointsVisible : true


  • @Refi
    In that case, I suggest making the transparent plot an XY scatter plot instead...


Log in to reply