Issue
How to show all the legend of Qpie? The words will become....
how should I solve this? Program screen
self.slice = self.series.slices()[1]
self.slice.setExploded()
self.slice.setLabelVisible()
self.slice.setPen(QPen(Qt.darkGreen, 2))
self.slice.setBrush(Qt.green)
#self.slice.setLabelBrush(labelBrush)
self.slice.setLabelFont(pieFont)
self.chart = QChart()
self.chart.addSeries(self.series)
self.chart.setTitle('History Data')
self.chart.legend().hide()
self.chart.createDefaultAxes()
self.chart.setFont(titleFont)
self.chart.setTitleFont(titleFont)
#self.chart.setBackgroundBrush(bgG)
#self.chart.setTitleBrush(QBrush(Qt.white))
self.chart.setAnimationOptions(QChart.SeriesAnimations)
self.chart.legend().setVisible(True)
self.chart.legend().setAlignment(Qt.AlignBottom)
self._chart_view = QChartView(self.chart)
self._chart_view.setRenderHint(QPainter.Antialiasing)
self.charWidget.setChart(self.chart)
Solution
The graph legend is not showing because the window width is small.
If you increase the screen width the subtitles will appear.
Note setFixedSize()
import sys
from PyQt5 import QtChart
from PyQt5.QtChart import QChartView, QChart
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QFont
from PyQt5.QtWidgets import QApplication, QMainWindow
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PyQtChart Pie Chart")
# without problem
self.setFixedSize(500, 300)
# with problem
self.setFixedSize(400, 300)
self.create_piechart()
self.show()
def create_piechart(self):
# serie
series = QtChart.QPieSeries()
series.append("l011111111111", 80)
series.append("l02", 70)
series.append("l03", 50)
series.append("l04", 40)
series.append("l05", 30)
series.append("l06", 80)
series.append("l07", 70)
series.append("l08", 50)
series.append("l09", 40)
series.append("l10", 30)
#chart
titleFont = QFont('Times', 28)
chart = QChart()
chart.addSeries(series)
chart.createDefaultAxes()
chart.setAnimationOptions(QChart.SeriesAnimations)
chart.setTitle('History Data')
chart.legend().hide()
chart.setFont(titleFont)
chart.setTitleFont(titleFont)
chart.legend().setVisible(True)
chart.legend().setAlignment(Qt.AlignBottom)
chartview = QChartView(chart)
chartview.setRenderHint(QPainter.Antialiasing)
#chartview.setChart(chart)
self.setCentralWidget(chartview)
if __name__ == '__main__':
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())
Hope this helps.
Answered By - Jonas Vieira de Souza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.