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

How to clear old point using qt charts when end of plot is reached?



  • Hi

    I am using line series to plot points. when wave reaches at the end of plot
    I want to clear the oldest point and plot a new point from the start of the plot.

    code:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtCharts 2.0
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        property var i: 0
        property var j: 0
        property var k: 0
        
        ChartView {
            title: "Line"
            anchors.fill: parent
            antialiasing: true
            ValueAxis {
                id: xAxis
                min: 0
                max: 10;
            }
            
            ValueAxis {
                id: yAxis
                min: 0
                max: 10
            }
            
            LineSeries {
                id: lineSer
                name: "LineSeries"
                axisX:  xAxis
                axisY:yAxis
            }
        }
        Timer {
            interval: 500; running: true; repeat: true
            onTriggered: {
                i = i + 0.5
                if(i > 10)
                {
                    i = 0
                    j = 1
                    k=k+1
                    
                }
                if(j===1)
                {
                    
                    lineSer.remove(0)
                }
                
                lineSer.append(i,k)
                
            }
            
        }
    }
    

    Screenshot 2020-01-13 at 3.36.12 PM.png

    I am able to clear the point but there is a line drawn from 10.0 to 0.0(digonal) probably due to append. So how can I eliminate this line as it is not needed?


Log in to reply