Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to plot this series in QML ChartView

How to plot this series in QML ChartView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 209 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sajjad Ali
    wrote on last edited by
    #1

    Hello, this code makes some series. I have connected it as an object to QML main file. I want to plot it in ChartView already made there. There is only XYPoint in documentation. How can I Plot this series.
    Code that generates series:

    auto series = new QLineSeries;
        for (int i = 0; i < 500; i++) {
            QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
            p.ry() += QRandomGenerator::global()->bounded(20);
            *series << p;
        }
        qmlRegisterSingletonInstance ("com.data.chart",1,0,"myData",series);
    

    Main QML:

    import QtQuick
    import QtCharts
    import com.data.chart
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        ChartView {
            title: "Line Chart"
            anchors.fill: parent
            antialiasing: true
            backgroundRoundness: 50
            backgroundColor: "black"
            LineSeries {
               // Hello Help Please
            }
        }
    }
    
    Main.cpp
    ...
    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QObject>
    #include <QPointF>
    #include <QtMath>
    #include <QRandomGenerator>
    #include <QQmlEngine>
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(u"qrc:/chart/main.qml"_qs);
        QObject::connect(
            &engine,
            &QQmlApplicationEngine::objectCreated,
            &app,
            [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl)
                    QCoreApplication::exit(-1);
            },
            Qt::QueuedConnection);
        engine.load(url);
    
        auto series = new QLineSeries;
        for (int i = 0; i < 500; i++) {
            QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
            p.ry() += QRandomGenerator::global()->bounded(20);
            *series << p;
        }
        qmlRegisterSingletonInstance ("com.data.chart",1,0,"myData",series);
    
        return app.exec();
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved