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. Can't dynamically update CandlestickSeries in QtCharts
Forum Updated to NodeBB v4.3 + New Features

Can't dynamically update CandlestickSeries in QtCharts

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 358 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
    SlayH
    wrote on last edited by
    #1
    import QtQuick 2.15
    import QtCharts 2.15
    
    Rectangle{
      width: 400;
      height: 400;
      radius: 40;
      property alias series: series;
    
      ChartView{
        id: chartView;
        anchors.fill: parent;
        title: "Candlestick Chart";
        legend.visible: false;
        antialiasing: true;
    
        CandlestickSeries{
          id: series;
          increasingColor: "green";
          decreasingColor: "red";
    
          function updateData(){
            series.clear();
            console.log("updateData called");
            for (var i = 0; i < stockProvider.stockData.length / 10; i++) {
              console.log(stockProvider.stockData[i].timestamp);
              var candlestick = Qt.createQmlObject(
                "import QtQuick 2.15; import QtCharts 2.15; CandlestickSet { " +
                "timestamp: " + stockProvider.stockData[i].timestamp + "; " +
                "open: " + stockProvider.stockData[i].open + "; " +
                "high: " + stockProvider.stockData[i].high + "; " +
                "low: " + stockProvider.stockData[i].low + "; " +
                "close: " + stockProvider.stockData[i].close + "; " +
                "}", series
                );
              series.append(candlestick);
              console.log(stockProvider.stockData[i].open);
            }
          }
        }
      }
    }
    

    This is how I tried to update the CandlestickSeries dynamically but it doesn't work. I had console.log the data for debug purposes and they are all present. For some reason the graph remains blank. Can someone help me please?

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

      Have you looked at HCandlestickModelMapper/VCandlestickModelMapper? It might be a better way to tie your series to a dynamic source of data.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SlayH
        wrote on last edited by
        #3

        Okay thanks I will give it a try.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SlayH
          wrote on last edited by
          #4
          import QtQuick 2.15
          import QtCharts 2.15
          
          Rectangle{
            width: 400;
            height: 400;
            radius: 40;
          
            ChartView{
              id: chartView;
              anchors.fill: parent;
              title: "Candlestick Chart";
              legend.visible: false;
              antialiasing: true;
          
              CandlestickSeries{
                id: series;
                increasingColor: "green";
                decreasingColor: "red";
          
                VCandlestickModelMapper{
                  id: modelMapper;
                  model: candleStickModel;
                  timestampRow: 1;
                  openRow: 2;
                  highRow: 3;
                  lowRow: 4;
                  closeRow: 5;
                  onModelChanged: {
                      console.log("Candlestick series data model updated");
                  }
                }
              }
            }
          }
          
          QVariant CandleStickModel::data(const QModelIndex &index, int role) const {
              if (!index.isValid() || index.row() >= _candleStickData.size()) {
                  return QVariant();
              }
          
              const class ::CandleStickData *candle{_candleStickData.at(index.row())};
          
              switch (CandleStickRoles(role)) {
              case TimestampRole:
                  return candle->timestamp();
              case OpenRole:
                  return candle->open();
              case CloseRole:
                  return candle->close();
              case HighRole:
                  return candle->high();
              case LowRole:
                  return candle->low();
              default:
                  return QVariant();
              }
          
              return QVariant();
          }
          

          I tried using a VCandlestickModelMapper but it still doesn't work. Where did I go wrong please?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kiovtorov
            wrote on last edited by
            #5

            Did you solve it?

            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