modify line and more like echarts
This commit is contained in:
parent
569088b4a2
commit
a16f63fe61
4 changed files with 42 additions and 7 deletions
|
@ -4,4 +4,4 @@ like [百度 echarts](http://echarts.baidu.com/demo.htmlhttp://echarts.baidu.com
|
||||||
|
|
||||||
### [Python3.5 or latter][PyQt5 PyQtChart]
|
### [Python3.5 or latter][PyQt5 PyQtChart]
|
||||||
|
|
||||||
### 1.[测试](test/) <a href="test">测试</a><br />
|
### [1.测试](test/)
|
|
@ -162,6 +162,40 @@ class ChartView(QChartView):
|
||||||
self.lineItem.setZValue(998)
|
self.lineItem.setZValue(998)
|
||||||
self.lineItem.hide()
|
self.lineItem.hide()
|
||||||
|
|
||||||
|
def mouseMoveEvent(self, event):
|
||||||
|
super(ChartView, self).mouseMoveEvent(event)
|
||||||
|
# 获取x和y轴的最小最大值
|
||||||
|
axisX, axisY = self._chart.axisX(), self._chart.axisY()
|
||||||
|
min_x, max_x = axisX.min(), axisX.max()
|
||||||
|
min_y, max_y = axisY.min(), axisY.max()
|
||||||
|
# 坐标系中左上角顶点
|
||||||
|
point_top = self._chart.mapToPosition(QPointF(min_x, max_y))
|
||||||
|
# 坐标原点坐标
|
||||||
|
point_bottom = self._chart.mapToPosition(QPointF(min_x, min_y))
|
||||||
|
step_x = (max_x - min_x) / (axisX.tickCount() - 1)
|
||||||
|
step_y = (max_y - min_y) / (axisY.tickCount() - 1)
|
||||||
|
# 把鼠标位置所在点转换为对应的xy值
|
||||||
|
x = self._chart.mapToValue(event.pos()).x()
|
||||||
|
y = self._chart.mapToValue(event.pos()).y()
|
||||||
|
index = round((x - min_x) / step_x)
|
||||||
|
pos_x = self._chart.mapToPosition(
|
||||||
|
QPointF(index * step_x + min_x, min_y))
|
||||||
|
# print(x, pos_x, index, index * step_x + min_x)
|
||||||
|
# 得到在坐标系中的所有series的类型和点
|
||||||
|
points = [(serie, serie.at(index))
|
||||||
|
for serie in self._chart.series() if min_x <= x <= max_x and min_y <= y <= max_y]
|
||||||
|
if points:
|
||||||
|
# 跟随鼠标的黑线条
|
||||||
|
self.lineItem.setLine(pos_x.x(), point_top.y(),
|
||||||
|
pos_x.x(), point_bottom.y())
|
||||||
|
self.lineItem.show()
|
||||||
|
self.toolTipWidget.show("", points, event.pos() + QPoint(20, 20))
|
||||||
|
else:
|
||||||
|
self.toolTipWidget.hide()
|
||||||
|
self.lineItem.hide()
|
||||||
|
|
||||||
|
'''
|
||||||
|
# 旧方式
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
super(ChartView, self).mouseMoveEvent(event)
|
super(ChartView, self).mouseMoveEvent(event)
|
||||||
# 获取x和y轴的最小最大值
|
# 获取x和y轴的最小最大值
|
||||||
|
@ -196,6 +230,7 @@ class ChartView(QChartView):
|
||||||
else:
|
else:
|
||||||
self.toolTipWidget.hide()
|
self.toolTipWidget.hide()
|
||||||
self.lineItem.hide()
|
self.lineItem.hide()
|
||||||
|
'''
|
||||||
|
|
||||||
def onSeriesHoverd(self, point, state):
|
def onSeriesHoverd(self, point, state):
|
||||||
if state:
|
if state:
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# QGraphicsView练习例子
|
# QGraphicsView练习例子
|
||||||
<br />
|
|
||||||
|
|
||||||
### [Python3.4.4 or Python3.5][PyQt5]
|
### [Python3.4.4 or Python3.5][PyQt5]
|
||||||
|
|
||||||
### 1.<a href="世界地图">世界地图</a><br />
|
### [1.世界地图](世界地图/)
|
||||||
|
|
||||||
### 2.<a href="添加QWidget">添加QWidget.py</a><br />
|
### [2.添加QWidget](添加QWidget.py)
|
||||||
<img src="ScreenShot/1.png" />
|
![添加QWidget](ScreenShot/1.png)
|
||||||
|
|
||||||
### 3.<a href="QChart ToolTip">QChartToolTipTest.py</a><br />
|
### [3.QChart ToolTip](QChartToolTipTest.py)
|
||||||
<img src="ScreenShot/2.gif" />
|
more like [line-stack](http://echarts.baidu.com/demo.html#line-stack)
|
||||||
|
![QChart ToolTip](ScreenShot/2.gif)
|
Binary file not shown.
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 139 KiB |
Loading…
Reference in a new issue