QML-QtCharts烛台系列中继器
我想用自定义类中的数据填充 我想我会像往常一样使用,但它似乎不起作用:QML-QtCharts烛台系列中继器,qt,qml,qtcharts,Qt,Qml,Qtcharts,我想用自定义类中的数据填充 我想我会像往常一样使用,但它似乎不起作用: ChartView { title: "Candlestick Series" width: 400 height: 300 CandlestickSeries { name: "Acme Ltd." increasingColor: "green" decreasingColor:
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
}
}
}
}
注释掉的部分(直接取自)工作正常
基于中继器的代码不生成数据点
如何动态填充烛台系列
注意:我也尝试过,但也失败了。中继器
不工作,因为烛台集
不是组件
CandlestickSeries
有一个方法。并可用于创建要动态更新的qml对象
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));
}
}
}
图表视图{
标题:“烛台系列”
宽度:400
身高:300
烛台系列{
名称:“Acme有限公司”
增加颜色:“绿色”
递减颜色:“红色”
物业型号:100
onSetsModelChanged:{
清除();
对于(var指数=0;指数
注意:在线Qml编译器不支持QtCharts,因此我没有测试代码。可能可以工作,但我没有测试以下代码
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"
}
}
不,基于实例化器的解决方案不起作用(图表上没有显示数据)。此外,当我使用实例化器时,应用程序(PySide2应用程序)在退出时崩溃。错误:Qt.createQmlObject():缺少父对象传递系列(CandlestickSeries
对象的id)而不是null
修复了上述错误,但图表上没有显示烛台。它也是CandlestickSet,不CandlesticksSet@user140345谢谢,我刚改了。