首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QML QtCharts CandlestickSeries中继器

QML QtCharts CandlestickSeries中继器
EN

Stack Overflow用户
提问于 2021-02-19 23:00:45
回答 2查看 101关注 0票数 2

我想用来自自定义类的数据填充CandlestickSeries

我想我会像往常一样使用Repeater,但它似乎不起作用:

代码语言:javascript
复制
ChartView {
    title: "Candlestick Series"
    width: 400
    height: 300

    CandlestickSeries {
        name: "Acme Ltd."
        increasingColor: "green"
        decreasingColor: "red"

        /*
        CandlestickSet { timestamp: 1435708800000; open: 690; high: 694; low: 599; close: 660 }
        CandlestickSet { timestamp: 1435795200000; open: 669; high: 669; low: 669; close: 669 }
        CandlestickSet { timestamp: 1436140800000; open: 485; high: 623; low: 485; close: 600 }
        CandlestickSet { timestamp: 1436227200000; open: 589; high: 615; low: 377; close: 569 }
        CandlestickSet { timestamp: 1436313600000; open: 464; high: 464; low: 254; close: 254 }
        */

        Repeater {
            model: 100
            delegate: CandlestickSet {
                timestamp: 1000 * 60 * index + 1436313600000
                open: 400; high: 500; low: 300; close: 380
            }
        }
    }
}

注释掉的部分(直接取自documentation)工作正常。

Repeater-based代码不生成任何数据点。

如何动态填充CandlestickSeries?

注意:我也尝试过an alternative approach using JS,但也失败了。

EN

回答 2

Stack Overflow用户

发布于 2021-02-20 21:22:26

Instantiator可能可以工作,但我没有测试以下代码。

代码语言:javascript
复制
Instantiator {
    model: 100
    delegate: CandlestickSet {
        timestamp: 1000 * 60 * index + 1436313600000
        open: 400; high: 500; low: 300; close: 380
    }
    onObjectAdded: series.insert(index, object)
    onObjectRemoved: series.remove(object)
}

ChartView {
    title: "Candlestick Series"
    width: 400
    height: 300

    CandlestickSeries {
        id: series
        name: "Acme Ltd."
        increasingColor: "green"
        decreasingColor: "red"
    }
}
票数 2
EN

Stack Overflow用户

发布于 2021-02-20 04:23:39

Repeater无法工作,因为CandlestickSet不是ComponentCandlestickSeries有一个append方法。createQmlObject可以用来动态地创建qml对象。

代码语言:javascript
复制
ChartView {
    title: "Candlestick Series"
    width: 400
    height: 300

    CandlestickSeries {
        name: "Acme Ltd."
        increasingColor: "green"
        decreasingColor: "red"

        property int setsModel: 100

        onSetsModelChanged: {
            clear();
            for (var index = 0; index < setsModel; ++index)
                append(Qt.createQmlObject(
                    "import QtQuick 2.0; import QtCharts 2.12; " + 
                    "CandlestickSet { timestamp: " + (1000 * 60 * index + 1436313600000) + "; " 
                    "open: 400; high: 500; low: 300; close: 380}", 
                    null));
        }
    }
}

注意:在线Qml编译器不支持QtCharts,所以我没有测试代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66279947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档