【发布时间】:2019-11-26 12:21:08
【问题描述】:
我正在构建包含 QCharts 的应用程序。一切正常,直到我将值轴更改为日期时间轴。现在我在图表上看不到任何系列。我正在尝试其他主题中提供的有关堆栈溢出的方法,但没有成功。
我正在尝试按照其他主题中的建议将日期时间更改为自纪元以来的毫秒,当我设置 x 轴的范围时 - 不幸的是,在 x 轴上使用此方法时,我看到纪元时间而不是当前时间。 当我像现在这样设置范围时,我在 x 轴上看到了正确的时间,但我没有看到任何系列。
我已经检查了系列 - 在 x、y 轴的范围内有正确的点。
我正在使用 python 3.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)
【问题讨论】: