How to do graph with QML
-
How to do graph with QML
-
Qt 5 comes with a "Canvas":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-canvas.html element where you can do simple painting, similar to html 5.
-
You can just as well use a custom QQuickPaintedItem with QPainter painting on top of it. I generally find QPainter easier to work with than the canvas, probably because I've used QPainter far more.
The canvas element was created to target HTML5 developers, so the API is modeled after the html canvas rather than QPainter, which IMO is the better drawing API.
-
Can you give me the example ?
-
http://qt-project.org/doc/qt-5.0/qtquick/customitems-painteditem.html
http://qt-project.org/doc/qt-5.0/qtquick/canvas.htmlSadly, the documentation for this examples still seems to be broken, but you can see how its done in the files.
-
Here are the fixed versions:
http://doc-snapshot.qt-project.org/qt5-stable/qtquick/customitems-painteditem.html
http://doc-snapshot.qt-project.org/qt5-stable/qtquick/canvas.htmlEdit: You can use "Qwt":http://qwt.sourceforge.net/ widgets to draw graphs in C++, but there is nothing similar in QML yet. You need to write your own graphing code -- read points, and then draw lines between the points
-
See https://qt.gitorious.org/qt/qtdeclarative/trees/stable/examples/quick/demos/stocqt for the StocQt example which uses the canvas to paint graphs and do other interesting things.
Cheers,
Chris. -
Great example, Chris! I forgot about that.
You can find a screenshot at http://doc-snapshot.qt-project.org/qt5-stable/qtquick/demos-stocqt.html . The chart code is in StockChart.qml
-
-
-
but this is a bit complex
this is a good runable example that help me very much...
i hope help you too
https://github.com/shuirna/QMLChartJs -
but this is a bit complex
this is a good runable example that help me very much...
i hope help you too
https://github.com/shuirna/QMLChartJs