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 getSeries(self): series = QPieSeries() slice0 = series.append('10%', 1) series.append('20%', 2) series.append('70%', 7) # 显示label文字 series.setLabelsVisible() series.setPieSize(0.5) # 使第一块突出显示 slice0.setLabelVisible() slice0.setExploded() # 设置第一块颜色 slice0.setColor(QColor(255, 0, 0, 100)) return series
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
def on_collect_finished(self): # 输出后缀统计扇形图 suffix_list = self.resopt.get_suffix_list(5) all = self.resopt.count_all() self.chart.removeAllSeries() series = QPieSeries() for (suffix, count) in suffix_list: series.append(suffix, count) all -= count if all > 0: series.append('others', all) series.setLabelsVisible(True) self.chart.addSeries(series) # 设置按键和进度条 self.collectPushButton.setEnabled(True) self.progressBar.hide()
def get_pie_series(self): """ TODO:订单管理界面点击统计调用该函数,计算订单管理界面当前搜索范围内所有订单 各大类 书的销售额 按以下格式放入 series.append('类别x%', 销售额) """ totals, classes = self.database.stat_2(*self.data) all_total = sum(totals) if all_total: series = QPieSeries() for i in range(len(totals)): if totals[i]: word = (classes[i] + ' %.2f' % (totals[i])) series.append(word, totals[i]) else: series = QPieSeries() series.append('无销售', 1) series.setLabelsVisible() series.setPieSize(0.7) return series
class DistributionPieChart(QChartView): """ Pie chart that shows the distribution of capital according to several criteria """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Chart self.chart = QChart() self.chart.setTheme(QChart.ChartThemeDark) self.chart.legend().hide() self.chart.createDefaultAxes() self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setBackgroundVisible(False) self.chart.setTitle(" ") self.chart.setTitleBrush(QBrush(QColor('white'))) self.setChart(self.chart) self.setRenderHint(QPainter.Antialiasing) self.setStyleSheet("border: 0px; background-color: rgba(0,0,0,0)") self.setupSeries() # Initialize to all mode def setupSeries(self, mode="all"): """ Chart gets updated displaying the new data. Modes: - all : distribution between all accounts - accs : distribution between portfolio accounts - cryptoaccs : distribution between crypto accounts - strategies : distribution between strategies """ # Series self.chart.removeAllSeries() # Remove any previous series self.series = QPieSeries() # Get data if mode == "all": data = balances.get_all_accounts( ) + cbalances.get_all_accounts_with_amount_fiat() elif mode == "accounts": data = balances.get_all_accounts() elif mode == "crypto": data = cbalances.get_all_accounts_with_amount_fiat() elif mode == "currency": data = [(confighandler.get_fiat_currency().upper(), balances.get_total_balance_all_accounts( )), ("BTC", cbalances.get_total_balance_all_accounts_fiat())] data.sort(key=lambda x: x[1]) # Sort # Set Chart Title self.total = sum([i[1] for i in data]) self.setDefaultTitle() # Add to series for d in data: self.series.append(d[0], d[1]) # Hide little slices' labels self.series.setLabelsVisible(True) for slc in self.series.slices(): if slc.angleSpan() < 5: slc.setLabelVisible(False) slc.setLabelArmLengthFactor(0.05) self.chart.addSeries(self.series) # Signals and functionality self.series.hovered.connect(self.selectSlice) def selectSlice(self, _slice, state): """ Highlight selected slice """ font = ChartTitleFont() if state: font.setPointSize(20) _slice.setLabelVisible(True) self.chart.setTitle( f"{int(_slice.value())} {confighandler.get_fiat_currency().upper()} {round(_slice.percentage()*100,1)}%") else: font.setBold(False) if _slice.angleSpan() < 5: _slice.setLabelVisible(False) _slice.setExploded(False) self.setDefaultTitle() _slice.setLabelFont(font) def setDefaultTitle(self): """ Sets title as total balance from all pie slices """ self.chart.setTitle( f"{int(self.total)} {confighandler.get_fiat_currency().upper()}") font = ChartTitleFont(fontsize=20) self.chart.setTitleFont(font)