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 ?
Asked
Active
Viewed 1,566 times
2
-
What do you mean by background color? Could you place an image that illustrates what you want to get – eyllanesc Jul 01 '21 at 23:01
-
@eyllanesc , I have added the chart image. If you see background is white color. Is there any way to change the bg color of chart. – Saurabh Jul 02 '21 at 03:50
1 Answers
3
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_())

eyllanesc
- 235,170
- 19
- 170
- 241