| 104 | class ChartView(QChartView): |
| 105 | |
| 106 | def __init__(self, *args, **kwargs): |
| 107 | super(ChartView, self).__init__(*args, **kwargs) |
| 108 | self.resize(800, 600) |
| 109 | self.setRenderHint(QPainter.Antialiasing) # 抗锯齿 |
| 110 | # 自定义x轴label |
| 111 | self.category = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] |
| 112 | self.initChart() |
| 113 | |
| 114 | # 提示widget |
| 115 | self.toolTipWidget = GraphicsProxyWidget(self._chart) |
| 116 | |
| 117 | # line |
| 118 | self.lineItem = QGraphicsLineItem(self._chart) |
| 119 | pen = QPen(Qt.gray) |
| 120 | pen.setWidth(1) |
| 121 | self.lineItem.setPen(pen) |
| 122 | self.lineItem.setZValue(998) |
| 123 | self.lineItem.hide() |
| 124 | |
| 125 | # 一些固定计算,减少mouseMoveEvent中的计算量 |
| 126 | # 获取x和y轴的最小最大值 |
| 127 | axisX, axisY = self._chart.axisX(), self._chart.axisY() |
| 128 | self.min_x, self.max_x = axisX.min(), axisX.max() |
| 129 | self.min_y, self.max_y = axisY.min(), axisY.max() |
| 130 | |
| 131 | def resizeEvent(self, event): |
| 132 | super(ChartView, self).resizeEvent(event) |