显示百分比和标签
Show percentage and label
我试图在 Qchart 中显示标签和百分比,但它只显示其中之一
有没有办法同时显示它们
这是我的功能,运行 QtChart
def charts_jr_acte(self):# pushButton_123
rightseries = QPieSeries()
rightseries.setLabelsVisible(True)
rightseries.setLabelsPosition(QPieSlice.LabelInsideHorizontal)
for C_acte, montant in rows:
rightseries.append(C_acte, montant)
slice = QPieSlice()
slice = rightseries.slices() [2]
slice.setExploded(True)
slice.setPen(QtGui.QPen(Qt.darkBlue))
for slice in rightseries.slices():
slice.setLabel("{:.2f}%".format(100 * slice.percentage()))
rightchart = QChart()
rightchart.createDefaultAxes()
rightchart.addSeries(rightseries)
rightchart.setTitle("total journalier de chaque Acte")
rightchart.setAnimationOptions(QChart.SeriesAnimations)
rightchart.legend().setVisible(True)
rightchart.legend().setAlignment(Qt.AlignBottom)
rightchart.legend().markers(rightseries)[1].setLabel(lab)
rightseries.setLabelsVisible()
rightseries.setLabelsPosition(QtChart.QPieSlice.LabelInsideHorizontal)
self.graphicsView_4.setChart(rightchart)
`
这是结果的一个例子
我找到了让它工作的方法
def charts_jr_acte(self):# pushButton_123
rightseries = QPieSeries()
rightseries.setLabelsVisible(True)
for C_acte, montant in rows:
rightseries.append(C_acte, montant)
slice = QPieSlice()
slice = rightseries.slices() [2]
slice.setExploded(True)
slice.setPen(QtGui.QPen(Qt.darkBlue))
for slice in rightseries.slices():
slice.setLabelVisible()
oldLabel=slice.label()
slice.setLabel((oldLabel+": %.1f%%" %(slice.percentage()*100) ))
rightchart = QChart()
rightchart.createDefaultAxes()
rightchart.addSeries(rightseries)
rightchart.setTitle("total journalier de chaque Acte")
rightchart.setAnimationOptions(QChart.SeriesAnimations)
rightchart.legend().setVisible(True)
self.graphicsView_4.setChart(rightchart)
这是它的样子
我试图在 Qchart 中显示标签和百分比,但它只显示其中之一
有没有办法同时显示它们
这是我的功能,运行 QtChart
def charts_jr_acte(self):# pushButton_123
rightseries = QPieSeries()
rightseries.setLabelsVisible(True)
rightseries.setLabelsPosition(QPieSlice.LabelInsideHorizontal)
for C_acte, montant in rows:
rightseries.append(C_acte, montant)
slice = QPieSlice()
slice = rightseries.slices() [2]
slice.setExploded(True)
slice.setPen(QtGui.QPen(Qt.darkBlue))
for slice in rightseries.slices():
slice.setLabel("{:.2f}%".format(100 * slice.percentage()))
rightchart = QChart()
rightchart.createDefaultAxes()
rightchart.addSeries(rightseries)
rightchart.setTitle("total journalier de chaque Acte")
rightchart.setAnimationOptions(QChart.SeriesAnimations)
rightchart.legend().setVisible(True)
rightchart.legend().setAlignment(Qt.AlignBottom)
rightchart.legend().markers(rightseries)[1].setLabel(lab)
rightseries.setLabelsVisible()
rightseries.setLabelsPosition(QtChart.QPieSlice.LabelInsideHorizontal)
self.graphicsView_4.setChart(rightchart)
` 这是结果的一个例子
我找到了让它工作的方法
def charts_jr_acte(self):# pushButton_123
rightseries = QPieSeries()
rightseries.setLabelsVisible(True)
for C_acte, montant in rows:
rightseries.append(C_acte, montant)
slice = QPieSlice()
slice = rightseries.slices() [2]
slice.setExploded(True)
slice.setPen(QtGui.QPen(Qt.darkBlue))
for slice in rightseries.slices():
slice.setLabelVisible()
oldLabel=slice.label()
slice.setLabel((oldLabel+": %.1f%%" %(slice.percentage()*100) ))
rightchart = QChart()
rightchart.createDefaultAxes()
rightchart.addSeries(rightseries)
rightchart.setTitle("total journalier de chaque Acte")
rightchart.setAnimationOptions(QChart.SeriesAnimations)
rightchart.legend().setVisible(True)
self.graphicsView_4.setChart(rightchart)
这是它的样子