Set Background Color of QChartView

2k Views Asked by At

Is it possible to change the background/face color of QBarSeries in pyqtchart? By default background is coming as white, is there any way to change it ?

enter image description here

1

There are 1 best solutions below

0
eyllanesc On

You must set the background color of the QChart using the setBackgroundBrush method:

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