赞
踩
QPieSeries类将数据以饼状图显示。
import sys from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt from PyQt5.QtChart import QPieSeries, QPieLegendMarker, QChart, QChartView class MyPieWindow(QWidget): def __init__(self, parent=None): super(MyPieWindow, self).__init__(parent) chart = QChart() chartView = QChartView() pieSeries = QPieSeries() slice0 = pieSeries.append("铁:%10", 1) pieSeries.append("铝:%20", 2) pieSeries.append("铜:%70", 7) pieSeries.setLabelsVisible() pieSeries.setPieSize(0.6) slice0.setExploded() # 外伸 slice0.setColor(QColor(255, 0, 150)) chart.setTitle("饼状图") chart.addSeries(pieSeries) chartView.setChart(chart) chartView.setRenderHint(QPainter.Antialiasing) vbox = QVBoxLayout() vbox.addWidget(chartView) self.setLayout(vbox) if __name__ == "__main__": app = QApplication(sys.argv) win = MyPieWindow() win.show() sys.exit(app.exec_())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。