76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
|
# coding: gb2312
|
|||
|
from PyQt5.QtWidgets import QApplication, QMainWindow
|
|||
|
from PyQt5.QtGui import QPainter, QColor, QFont
|
|||
|
from PyQt5.QtCore import Qt
|
|||
|
|
|||
|
class MainWindow(QMainWindow):
|
|||
|
def __init__(self):
|
|||
|
super().__init__()
|
|||
|
|
|||
|
self.resize(800, 200)
|
|||
|
|
|||
|
# <20>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
self.x = ["2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>8ʱ", "2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>8ʱ", "2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>13<EFBFBD><EFBFBD>15ʱ", "2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>17<EFBFBD><EFBFBD>8ʱ", "2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>20<EFBFBD><EFBFBD>15ʱ", "2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>24<EFBFBD><EFBFBD>8ʱ",
|
|||
|
"2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>26<EFBFBD><EFBFBD>15ʱ", "2024<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>30<EFBFBD><EFBFBD>8ʱ", "2024<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>3<EFBFBD><EFBFBD>8ʱ", "2024<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>8<EFBFBD><EFBFBD>8ʱ", "2024<EFBFBD><EFBFBD>5<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>15ʱ"]
|
|||
|
|
|||
|
self.bar_width = self.width() // len(self.x) - 30 # <20><><EFBFBD>ݴ<EFBFBD><DDB4>ڿ<EFBFBD><DABF>Ⱥ<EFBFBD><C8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>
|
|||
|
self.x_offset = 50 # <20><><EFBFBD><EFBFBD> x <20><><EFBFBD><EFBFBD>ʼƫ<CABC><C6AB>
|
|||
|
|
|||
|
def resizeEvent(self, event):
|
|||
|
self.height_ratio = self.height() / 100 # <20><><EFBFBD><EFBFBD><EFBFBD>߶ȱ<DFB6><C8B1><EFBFBD>
|
|||
|
|
|||
|
def paintEvent(self, event):
|
|||
|
painter = QPainter(self)
|
|||
|
|
|||
|
y2 = [7.14, 7.14, 7.14, 7.14, 7.14, 7.14, 12.5, 14.29, 14.29, 16.07, 17.86]
|
|||
|
y1 = [42.86, 42.86, 42.86, 42.86, 42.86, 42.86, 37.5, 41.07, 42.86, 41.07, 39.29]
|
|||
|
y3 = [17.86, 17.86, 17.86, 17.86, 17.86, 17.86, 17.86, 12.5, 12.5, 14.29, 16.07]
|
|||
|
y4 = [2.14, 22.14, 32.14, 32.14, 32.14, 32.14, 32.14, 32.14, 30.36, 28.57, 26.79]
|
|||
|
y5 = [30, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|||
|
|
|||
|
gap = 15 # <20><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD> x <20><>
|
|||
|
painter.setPen(QColor('black'))
|
|||
|
font = QFont()
|
|||
|
font.setPointSize(10)
|
|||
|
painter.setFont(font)
|
|||
|
for i in range(len(self.x)):
|
|||
|
painter.drawText(self.x_offset - 20 + i * (self.bar_width + gap) + self.bar_width // 2, self.height() - 10, self.x[i])
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD> y <20><>
|
|||
|
painter.setPen(QColor('black'))
|
|||
|
for y_value in range(0, 101, 20):
|
|||
|
painter.drawText(20, int(self.height() - 40 - y_value * self.height_ratio), str(y_value))
|
|||
|
|
|||
|
for i in range(len(self.x)):
|
|||
|
# <20><><EFBFBD><EFBFBD> y1 <20><><EFBFBD><EFBFBD>
|
|||
|
painter.setBrush(QColor('green'))
|
|||
|
painter.drawRect(self.x_offset + i * (self.bar_width + gap), self.height() - int((y1[i] + 20) * self.height_ratio), self.bar_width, int(y1[i] * self.height_ratio))
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD> y2 <20><><EFBFBD><EFBFBD>
|
|||
|
painter.setBrush(QColor('blue'))
|
|||
|
painter.drawRect(self.x_offset + i * (self.bar_width + gap), self.height() - int((y1[i] + y2[i]) * self.height_ratio), self.bar_width,
|
|||
|
int(y2[i] * self.height_ratio))
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD> y3 <20><><EFBFBD><EFBFBD>
|
|||
|
painter.setBrush(QColor('red'))
|
|||
|
painter.drawRect(self.x_offset + i * (self.bar_width + gap), self.height() - int((y1[i] + y2[i] + y3[i]) * self.height_ratio), self.bar_width,
|
|||
|
int(y3[i] * self.height_ratio))
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD> y4 <20><><EFBFBD><EFBFBD>
|
|||
|
painter.setBrush(QColor('yellow'))
|
|||
|
painter.drawRect(self.x_offset + i * (self.bar_width + gap), self.height() - int((y1[i] + y2[i] + y3[i] + y4[i]) * self.height_ratio),
|
|||
|
self.bar_width, int(y4[i] * self.height_ratio))
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD> y5 <20><><EFBFBD><EFBFBD>
|
|||
|
painter.setBrush(QColor('purple'))
|
|||
|
painter.drawRect(self.x_offset + i * (self.bar_width + gap),
|
|||
|
self.height() - int((y1[i] + y2[i] + y3[i] + y4[i] + y5[i]) * self.height_ratio), self.bar_width, int(y5[i] * self.height_ratio))
|
|||
|
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
app = QApplication([])
|
|||
|
window = MainWindow()
|
|||
|
window.show()
|
|||
|
app.exec_()
|