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 Dynamically Load Candlesticks in QML
Forum Updated to NodeBB v4.3 + New Features

How to Dynamically Load Candlesticks in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 252 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.
  • K Offline
    K Offline
    Kiovtorov
    wrote on last edited by
    #1

    Does someone have a working example of dynamically loading candlesticks because I have tried numerous variants but none of them worked

    import QtQuick
    import QtCharts
    import QtQuick.Controls
    
    Window {
        id: root
        visible: true
        width: 800
        height: 600
    
        ChartView {
            id: chart
            anchors.fill: parent
            title: "Candlestick Chart Example"
            antialiasing: true
    
            CandlestickSeries {
                id: candleSeries
                name: "Stock Data"
                increasingColor: "green"
                decreasingColor: "red"
            }
        }
    
        Button {
            text: "Add Candlestick"
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: root.addCandlestick()
            background: Rectangle
            {
                color: "black"
            }
        }
    
        function addCandlestick() {
            let open = Math.random() * 100 + 50;
            let high = open + Math.random() * 10;
            let low = open - Math.random() * 10;
            let close = low + Math.random() * (high - low);
    
            // Create a CandlestickSet instance using the correct method
            let set = Qt.createQmlObject(`
                import QtCharts 2.15;
                CandlestickSet {
                    timestamp: ` + Date.now() + `;
                    open: ` + open + `;
                    high: ` + high + `;
                    low: ` + low + `;
                    close: ` + close + `;
                }
            `, candleSeries);
    
            candleSeries.append(set);
        }
    }
    

    or

        function addCandlestick() {
            let open = Math.random() * 100 + 50;
            let high = open + Math.random() * 10;
            let low = open - Math.random() * 10;
            let close = low + Math.random() * (high - low);
    
            let candlestick = Qt.createComponent("QtCharts.CandlestickSet");
            let set = candlestick.createObject(candleSeries, { timestamp: Date.now(), open, high, low, close });
    
            candleSeries.append(set);
        }
    

    etc...

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bob64
      wrote on last edited by Bob64
      #2

      I wonder if there is a bug in Qt. In the debugger I see count go up on candleSeries each time a CandlestickSet is added, but like you I see nothing on the chart. (I am using Qt 5.15 - so this doesn't seem to be an issue with specific versions.)

      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