def create_predict_pieseries(self, bots_part): human_part = 1 - bots_part percentage_bots_part = int(round(bots_part * 100)) percentage_human_part = 100 - percentage_bots_part # define the series slices of the pie series = QPieSeries() bot_slice = QPieSlice(f"Bot ({percentage_bots_part}%)", bots_part) human_slice = QPieSlice(f"Human ({percentage_human_part}%)", human_part) font = QFont() font.setBold(True) bot_slice.setColor(QColor("#3498db")) bot_slice.setLabelFont(font) human_slice.setColor(QColor("#a8e6cf")) human_slice.setLabelFont(font) series.append(bot_slice) series.append(human_slice) series.setLabelsVisible(False) series.setLabelsPosition(QPieSlice.LabelInsideHorizontal) series.setPieSize(0.94) return series
class Chart(QWidget): def __init__(self, chartKey, data, frame, parent=None): super(Chart, self).__init__(parent) self.frame = frame self.data = data self.create_chart(chartKey) def create_chart(self, chartKey): self.series = QPieSeries() self.series.setHoleSize(0.35) self.chart = QChart() #Add series to the chart self.addSeries(chartKey) # for the background and title self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setTitle("Code Size Visualizer") self.chart.legend().setVisible(True) self.chart.legend().setAlignment(Qt.AlignRight) self.chart.setTheme(QChart.ChartThemeBlueCerulean) self.chartview = QChartView(self.chart) self.chartview.setRenderHint(QPainter.Antialiasing) #each section of the pie chart def addSeries(self, key): self.chart.removeAllSeries() self.series = QPieSeries() self.series.setHoleSize(0.35) #Show chartview only if the content length is less than 6. Otherwise show a table view if len(self.data[key]) < 6: #print('length',self.data, key) for key, value in self.data[key].items(): print('key, value', key, value) slice_ = QPieSlice(str(key), value) self.series.append(slice_) self.series.setLabelsVisible() self.series.setLabelsPosition(QPieSlice.LabelInsideHorizontal) for slice in self.series.slices(): #slice.setLabel(slice.label()) slice.setLabel(slice.label() + ' - ' + str(slice.value()) + ' B ') self.chart.addSeries(self.series) self.frame.frame.hide() self.chart.show() else: self.table = TableView(self.data[key], len(self.data[key]), 1) if self.frame.ly.count() > 0: self.frame.ly.itemAt(0).widget().setParent(None) self.frame.ly.addWidget(self.table) self.frame.frame.show() self.chart.hide()
def create_initialize_pieseries(self): color = QColor("#757a79") # define the series slices of the pie series = QPieSeries() none_slice = QPieSlice("Undefined", 1.0) none_slice.setColor(color) none_slice.setBorderColor(color) series.append(none_slice) series.setLabelsVisible(False) series.setLabelsPosition(QPieSlice.LabelOutside) series.setPieSize(0.94) return series