我正在构建包括QCharts的应用程序。在我将Value轴更改为DateTime轴之前,一切都正常。现在我在图表上看不到任何序列。我在尝试其他主题中提供的关于堆栈溢出的方法,但没有成功。在
我正试图像其他主题中建议的那样,将datetime更改为毫秒,因为我正在设置x轴的范围-不幸的是,在x轴上使用这个方法,我看到的是epoch时间而不是当前时间。 当我像现在这样设置范围时,我在x轴上看到了正确的时间,但我没有看到任何序列。在
我检查了序列-在x,y轴的范围内有正确的点。在
我使用的是python3.7和pyside2。在
self.plot = QtCharts.QChart()
self.add_series("Magnitude (Column 1)", [0, 1])
self.chart_view = QtCharts.QChartView(self.plot)
self.series = QtCharts.QLineSeries()
self.series.setName(name)
self.plot.addSeries(self.series)
# Setting X-axis
self.axis_x = QtCharts.QDateTimeAxis()
self.axis_x.setTickCount(10)
self.axis_x.setLabelsAngle(70)
self.axis_x.setFormat("dd.MM.yy h:mm:ss")
self.axis_x.setTitleText("Date")
self.axis_x.setMax(QDateTime.currentDateTime().addSecs(60))
self.axis_x.setMin(QDateTime.currentDateTime())
# Setting Y-axis
self.axis_y = QtCharts.QValueAxis()
self.axis_y.setTickCount(7)
self.axis_y.setLabelFormat("%i")
self.axis_y.setTitleText("Temperature [celcious]")
self.axis_y.setMax(30)
self.axis_y.setMin(20)
self.series.attachAxis(self.axis_x)
self.series.attachAxis(self.axis_y)
self.plot.addAxis(self.axis_x, Qt.AlignBottom)
self.plot.addAxis(self.axis_y, Qt.AlignLeft)
...
# Add points to the chart
def addPoint(self):
x = QDateTime.currentDateTime().toSecsSinceEpoch()
y = float(20+self.i)
self.series.append(x, y)
print(self.series.points())
self.i += 1
print(QDateTime.currentDateTime().toMSecsSinceEpoch(),y)
必须使用toMSecsSinceEpoch()方法,而不是toSecsSinceEpoch()。另一方面,我发现每次添加数据时都需要确定范围(可能是QtCharts错误)。在
考虑到上述情况,解决方案是:
相关问题 更多 >
编程相关推荐