Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abnormalities in Qml spline chart

When creating a spline chart, it is getting loops inside the chart and some portions are going beyond the chart panel. Please find the below code

 ChartView {
    title: "Spline"
    anchors.fill: parent
    antialiasing: true

    SplineSeries {
        name: "SplineSeries"
        XYPoint { x: 154593917; y: 612.5 }
        XYPoint { x: 154594277; y: 425 }
        XYPoint { x: 154594632; y: 437 }
        XYPoint { x: 154594997; y: 460 }
        XYPoint { x: 154595357; y: 506 }
        XYPoint { x: 154596073; y: 513 }
        XYPoint { x: 154596437; y: 527 }
        XYPoint { x: 154596797; y: 575 }
        XYPoint { x: 154597517; y: 632 }
        XYPoint { x: 154597877; y: 369 }
        XYPoint { x: 154598237; y: 410 }
        XYPoint { x: 154598851; y: 414 }
        XYPoint { x: 154604971; y: 633 }
        XYPoint { x: 154605331; y: 598 }
        XYPoint { x: 154605400; y: 500 }
    }
}

How to remove this looping? Please help

enter image description here

like image 741
Masthan Avatar asked Dec 30 '18 15:12

Masthan


1 Answers

The problem comes from the fact that SplineSeries is creating, well, a spline (piecewise polynomials) to interpolate your points. QtCharts doesn't provide any control on spline parameters, such as degree, control points, etc. All of them are automatically computed from the dataset.

You should take care of the nature of the spline: they will pass through the data points, but the rest of the points will be approximated by the under-the-hood polynomial function, so creating unexpected points. In order to create the piecewise curve, some constraints must be met, such as C0, C1 and C2continuity (assuming a cubic spline). In your case, the curve must create these loops in order to meet such constraints.

QtCharts doesn't provide many XY plotting options: basically ScatterSeries (plots single points), LineSeries (linear interpolation, no options for smoothing) and SplineSeries (smooth, spline-based interpolation).

To use another one, just replace the node SplineSeries by LineSeries. Here you have an example of how they look like with your data:

series comparison

As a mid-point solution, you can preprocess your data using some other interpolating method that better adapts to your requirements (such a composite Bèzier curves), and then evaluate the curve in more points to create a smoother data, more friendly with SplineSeries or, if it looks good-enough for you, that can be directly rendered using LinesSeries.

like image 125
cbuchart Avatar answered Oct 19 '22 17:10

cbuchart