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

Return interpolated values from QLineSeries



  • Hi -

    Is there a way to return the interpolated values - i.e. what a QChart actually draws once you feed it a line series? For example, if I feed it the series (1,1) and (4, 4), it will draw a sloped line between the two points, so is there a way to return what it interpolated for the y value at x=2 and x=3? Can I take that further, and go down to the decimal level, so I can control every pixel's width of graph?

    For context, I'm drawing a color gradient across a chart under a graphed line, but I need the drawing to stop vertically at the line - so I need the y value of the line at every pixel value along the x-axis.



  • First, you need to know there are different ways to interpolate among a data set. It is totally up to you how to do it. Linear or higher order? It is not hard to find where 2 or 3 is located and write a small function to get what you need.



  • That's true, I definitely can do the interpolation, I'm just avoiding it both because Qt has already done it somewhere in the backend, and because it's going to be messy - as I mentioned I need to draw a vertical line for every pixel's width of the QChart, so it'll be a slope between every point, and then draw up to whatever height it needs. It would be nice to get the smoothness of a spline series as well, but I guess that's just higher order interpolation. I guess what I'm looking for is a way to return a vector of points that describe where, in pixel values, the QChart has drawn the line, but that might be too much to ask. ;)

    Thanks for your response - I'll probably do the interpolation myself unless someone else knows the magic function call!


Log in to reply