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

Efficient autoscale chart



  • Hello everyone,

    could you please suggest best (performance-wise) method to draw on a "rolling / moving" chart based on QPixmap. I cannot use QtCharts due to licensing restrictions (and I do not want to use chart.js - not performant enough on mobile platform...). I am building for Andorid.

    My current solution:

    I have a QQuickPaintedItem derived object which is used to paint the chart - here I am painting "already prepared" QPixmap object with drawPixmap method in the paint routine... So, a simple painter->drawPixmap(...) call. No optimizations more to be done here. (currently I am not looking into OpenGL, althoug as far as I understand OpenGL rendering is used).

    The "already prepared" QPixmap is painted on another thread, which takes care of adding new points / lines, manages vertical and horizontal ticks and labels. Since this is a moving chart (with autoscaling) everything needs to be re-painted when a new point is added.

    I am using QMap<QString, QVector<QPointF>* > to enable multiple plot id (hence the QString key). The reason I am using a pointer to QVector<QPointF> is to call reserve method on newly created plot ids. Then it's a simple iteration over QVector<QPointF> for each plot id and painting on QPixmap (prior to painting, the pixmap is cleared using fill(Qt::transparent). Of course, every new point is appended to the QVector<QPointF>.

    When the painting is done, the QPixmap object is sent as a constant reference to the frontend via signal / slot mechanism where the QQuickPainted item is updated...

    Although I get a reasonable performance, I would like to know what improvements can I make to further optimize this?
    Using plain logic, the best way would be to draw only the new points / lines. But I still need to retain a moving / autoscaling chart. Any suggestions please?

    P.S.: Currently, I am using no buffer size limit (I will eventually). In that case I could take the appropriate region of the previous pixmap and paint only the new points / lines on the "chart". Then, I would not need to iterate through the container...

    Thank you for any suggestions.

    Have a nice day,
    K



  • QWT is no option?



  • @NachoFly thank you for the suggestion. I suppose I could look into this - I see that the source code can be kept private by dynamically linking the qwt lib... Do you have any good sources for qwt on Android - I would need QML integration also, but I suppose this shouldn't be such a problem. Still, I don't know if there are any performance improvements as opposed to my current solution?

    Regards,
    K


Log in to reply