gpt4 book ai didi

javascript - 在 QML 中绘制 LineSeries 图表

转载 作者:行者123 更新时间:2023-12-03 03:44:37 26 4
gpt4 key购买 nike

我是 Qt/QML 的新手,我需要在 QML 中绘制图表,其 X 轴上的格式时间(例如:00:05(格式为 hh:mm))。在 Qt 文档中我找到了一个示例:

    ChartView {
title: "Accurate Historical Data"
anchors.fill: parent
legend.visible: false
antialiasing: true

LineSeries {
axisX: DateTimeAxis {
format: "yyyy MMM"
tickCount: 5
}
axisY: ValueAxis {
min: 0
max: 150
}

// Please note that month in JavaScript months are zero based, so 2 means March
XYPoint { x: toMsecsSinceEpoch(new Date(1950, 2, 15)); y: 5 }
XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 }
XYPoint { x: toMsecsSinceEpoch(new Date(1987, 12, 31)); y: 102 }
XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 }
XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 2)); y: 110 }
}
}

// DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to
// milliseconds since epoch to make them match the DateTimeAxis values
function toMsecsSinceEpoch(date) {
var msecs = date.getTime();
return msecs;
}

如何使用时间而不是日期设置 X 轴的值?非常感谢您的帮助

最佳答案

您可以在 Date 构造函数中指定(更)准确的时间。

XYPoint{ x: toMsSinceEpoch(new Date(2017, 9, 27, 15, 29, 21)), y: 5 }

https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Date

然后可以设置X轴格式显示小时和秒:

DateTimeAxis {
....
format: "hh:mm"
}

关于javascript - 在 QML 中绘制 LineSeries 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45457549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com