QBarSeries背景颜色

问题描述

是否可以在pyqtchart中更改QBarSeries的背景/面部颜色?默认情况下背景为白色,是否可以更改它?

解决方法

您必须使用 setBackgroundBrush 方法设置 QChart 的背景颜色:

import sys

from PyQt5.QtGui import QBrush,QColor,QPainter
from PyQt5.QtWidgets import QApplication
from PyQt5.QtChart import QChartView,QPieSeries

app = QApplication(sys.argv)

series = QPieSeries()
series.setHoleSize(0.35)

for l,v in (("ABC",10),("PQR",30),("XYZ",60)):
    slice = series.append(l,v)
    slice.setLabelVisible()

view = QChartView()
view.setRenderHint(QPainter.Antialiasing)
view.chart().addSeries(series)
view.chart().setBackgroundBrush(QBrush(QColor("salmon")))
view.resize(640,480)
view.show()

sys.exit(app.exec_())

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...