How to Dynamically Load Candlesticks in QML
Unsolved
QML and Qt Quick
-
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...
-