Can someone provide a working example of VXYModelMapper with lineseries chart ?



  • I want to implement something like this .With a model from cpp and combined with line charts but I am not able to understand yColumn and xColumn as in what data shall I provide it and I would like to Append the data to the lineseries every time it is updated.

    qml:
    
    
    Rectangle {
        implicitWidth: implicitWidth + 2*anchors.margins
        implicitHeight: implicitHeight + 2*anchors.margins
        clip: true
        color: "#ddd"
        Item {
        id: valueDisp
        implicitWidth: 640
        implicitHeight: 640
    
        ChartView
        {
            id: chartView
            title: " Scope "
            anchors.fill: parent
            legend.visible: false
            antialiasing: true
            backgroundColor: "white"
            plotAreaColor: "white"
            titleColor: "white"
    
            ValueAxis {
                id: axisX
                titleText:componentData.readXAxisName
                min: componentData.changeXMin
                max: componentData.changeXMax
                tickCount: 1
            }
    
            ValueAxis {
                id: axisY
                titleText:componentData.readYAxisName
                min: componentData.changeYMin
                max: componentData.changeYMax
                tickCount: 1
            }
    
            LineSeries {
    
                id: lineSeries
                name: "Data Output"
                axisX: axisX
                axisY: axisY
                useOpenGL: true
                VXYModelMapper{
                model:componentData.dataRead
                }
            }
        }
    

    cpp:

    
    //this is a snippet of the code I am using :
    // in class ScopeData I a updating setXdata and setYdata and whenever I update them I assert valueAdded signal as well 
    Q_PROPERTY(QQmlListProperty<ChartData> dataRead READ dataRead NOTIFY valueAdded)
    
    QQmlListProperty<ChartData> ScopeData::dataRead()
    {
    	return QQmlListProperty<xpcv::ChartData> (this,m_chartData);
    }
    
    // these are the functions that I am using to update the data in the chart
    ChartData::ChartData(QObject *parent)
    	: QObject(parent),
    		m_xValue(0), 
    		m_yValue(0)
    	{}
    	void ChartData::setXdata(int data)
    	{
    		m_xValue=data;
    	}
    
    	void ChartData::setYdata(double data)
    	{
    		m_yValue=data;
    	}
    

    but I get the following error:
    unable to assign qmlListProperty<ChartData> to QAbstractItemModel
    PS- I cannot share the entire code because of privacy of project details
    Thank You,
    Saransh Vora



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