def get_performace_chart(): # Graph is based on data of: # 'Total consumption of energy increased by 10 per cent in 2010' # Statistics Finland, 13 December 2011 # http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html series1 = QtCharts.QPieSeries() series1.setName("Business Logic") series1.append("User Input", 353295) series1.append("Card Processing", 188500) series1.append("Others", 148680) series2 = QtCharts.QPieSeries() series2.setName("Communications") series2.append("Payment ", 319663) series2.append("Reversal", 45875) series2.append("Advice", 1060) series2.append("DCC", 111060) series3 = QtCharts.QPieSeries() series3.setName("Printing") series3.append("Merchant Receipt", 238789) series3.append("Customer Receipt", 37802) donut_breakdown = DonutBreakdownChart() donut_breakdown.setAnimationOptions(QtCharts.QChart.AllAnimations) donut_breakdown.setTitle("Total Transaction time") donut_breakdown.legend().setAlignment(Qt.AlignRight) donut_breakdown.add_breakdown_series(series1, Qt.red) donut_breakdown.add_breakdown_series(series2, Qt.darkGreen) donut_breakdown.add_breakdown_series(series3, Qt.darkBlue) chart_view = QtCharts.QChartView(donut_breakdown) chart_view.setRenderHint(QPainter.Antialiasing) return chart_view
def create_piechart(self): #Creates pie chart data. self.series = QtCharts.QPieSeries() self.series.append("DoS", 0) self.series.append("DDoS", 0) self.series.append("Benign", 0) self.series.append("SSH", 0) self.series.append("FTP", 0) #Adds slice. slice = QtCharts.QPieSlice() slice = self.series.slices()[2] slice.setExploded(True) slice.setLabelVisible(True) slice.setPen(QtGui.QPen(QtCore.Qt.darkGreen, 2)) slice.setBrush(QtCore.Qt.green) #Create chart. self.chart = QtCharts.QChart() self.chart.legend().hide() self.chart.addSeries(self.series) self.chart.createDefaultAxes() self.chart.setTitle("Attacks Pie Chart") #Adds legend. self.chart.legend().setVisible(True) self.chart.legend().setAlignment(QtCore.Qt.AlignBottom) self.chart.setBackgroundVisible(False) #Render pie chart. chartview = QtCharts.QChartView(self.chart) chartview.setRenderHint(QtGui.QPainter.Antialiasing) return chartview
def updatePieChart(self): #Remove data from pie chart. self.chart.removeSeries(self.series) #Creates new pie chart data -> series. self.series = QtCharts.QPieSeries() self.series.append("Benign", self.benignFlows) item = self.series.append("DoS", self.DoS) item.setBrush(QtGui.QColor("salmon")) item = self.series.append("DDoS", self.DDoS) item.setBrush(QtGui.QColor("blue")) item = self.series.append("SSH", self.SSH) item.setBrush(QtGui.QColor(0, 255, 255)) item = self.series.append("FTP", self.FTP) item.setBrush(QtGui.QColor(255, 0, 255)) #Adds slice. slice = QtCharts.QPieSlice() slice = self.series.slices()[0] slice.setExploded(True) slice.setLabelVisible(True) slice.setPen(QtGui.QPen(QtCore.Qt.darkGreen, 2)) slice.setBrush(QtCore.Qt.green) #Adds data to pie chart. self.chart.addSeries(self.series)
def __init__(self): QMainWindow.__init__(self) self.series = QtCharts.QPieSeries() self.series.append('Jane', 1) self.series.append('Joe', 2) self.series.append('Andy', 3) self.series.append('Barbara', 4) self.series.append('Axel', 5) 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.chart = QtCharts.QChart() self.chart.addSeries(self.series) self.chart.setTitle('Simple piechart example') self.chart.legend().hide() self.chartView = QtCharts.QChartView(self.chart) self.chartView.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(self.chartView)
def __init__(self, parent=None): super(DonutBreakdownChart, self).__init__(QtCharts.QChart.ChartTypeCartesian, parent, Qt.WindowFlags()) self.main_series = QtCharts.QPieSeries() self.main_series.setPieSize(0.7) self.addSeries(self.main_series)
def createPieChart(data): chart = QtCharts.QChart() # chart.legend().hide() chart.setTitle("Pie chart (refugees as of 2017)") series = QtCharts.QPieSeries() sliceList = list( map(lambda nv: QtCharts.QPieSlice(nv[0], nv[1]), zip(data[0], data[1]))) series.append(sliceList) for s in series.slices(): s.setLabelVisible() chart = QtCharts.QChart() chart.addSeries(series) chart.setTitle("Simple piechart example") # chart.legend()->hide(); chartView = QtCharts.QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) return chartView
def setPieChartData(self, data: List[Tuple[str, int]]): pieSeries = QtCharts.QPieSeries() for name, value in data: pieSeries.append(name, value) chartPie = QtCharts.QChart() chartPie.addSeries(pieSeries) chartPie.setAnimationOptions(QtCharts.QChart.SeriesAnimations) chartPie.setTitle("Rating history") self.chartPieView.setChart(chartPie)
def plotpie(): pies = QtCharts.QPieSeries() #將一個圓餅圖物件放入pies裡面 for i in range(left_.rowCount()): #用for迴圈將讀取欄 word = left_.item(i, 0).text() #item第一個參數是跑rowCount(), 0是指取左邊那一欄的文字 cost = left_.item(i, 1).text() #第一個參數是跑過rowCount(), 1是指取右邊那一欄文字 pies.append(word, float(cost)) #將文字和數字加入pies裡面 chart = QtCharts.QChart() #製作一個Chart畫布物件,放入chart裡面 chart.addSeries(pies) #將pies資訊放入chart裡面 chart.legend().setAlignment(Qt.AlignTop) #文字往上對齊 right_chart.setChart(chart) #將chart資訊放入right_chart裡面
def add_chart(self): self.pie = QtCharts.QPieSeries() items_temp = self.items while self.items > 0: self.pie.append( self.table.item(self.items - 1, 0).text(), float(self.table.item(self.items - 1, 1).text())) self.items -= 1 self.items = items_temp self.chart = QtCharts.QChart() self.chart.addSeries(self.pie) self.chart_view.setChart(self.chart)
def plot_data(self): # Get table information series = QtCharts.QPieSeries() for i in range(self.table.rowCount()): text = self.table.item(i, 0).text() number = float(self.table.item(i, 1).text()) series.append(text, number) chart = QtCharts.QChart() chart.addSeries(series) chart.legend().setAlignment(Qt.AlignLeft) self.chart_view.setChart(chart)
def refresh_probs_tab(self): self.probs_chart.removeAllSeries() if self.cell is not None: info = self.data_tools.get_probs_info_for_cell( self.cell) #[(sym_label, prob), ...] series = QtCharts.QPieSeries() for (label, prob) in info: qslice = QtCharts.QPieSlice(label, prob) series.append(qslice) series.setLabelsVisible(True) self.probs_chart.addSeries(series)
def compose_series(self, categories): series = QtCharts.QPieSeries() colors = self.get_colors(categories) total = sum(categories.values()) for i, category_name in enumerate(categories): amount = categories[category_name] title = self.get_chart_slice_title(categories, category_name, amount, total) series.append(title, amount) slice = series.slices()[i] slice.setBrush(colors[i]) return series
def creador_pieseries(self, lista_pieslice, marcaindice=[]): pieSeries = QtCharts.QPieSeries() for indice, sli in enumerate(lista_pieslice): if (indice in marcaindice): sli.setExploded(True) # resalta por indice pieSeries.append(sli) pieSeries.setHoleSize(0.0) # agujero tamaño pieSeries.setPieSize(0.6) # pie tamaño pieSeries.setLabelsVisible(True) return pieSeries
def createPieChart(self): chart = QtCharts.QChart() chart.setTitle("Pie chart") series = QtCharts.QPieSeries(chart) for data in self.data_table[0]: slc = series.append(data[1], data[0].y()) if data == self.data_table[0][0]: # Show the first slice exploded with label slc.setLabelVisible() slc.setExploded() slc.setExplodeDistanceFactor(0.5) series.setPieSize(0.4) chart.addSeries(series) return chart
def testCharts(self): self.series = QtCharts.QPieSeries() self.series.append("Jane", 1) self.series.append("Joe", 2) self.series.append("Andy", 3) self.series.append("Barbara", 4) self.series.append("Axel", 5) slice = self.series.slices()[1] slice.setExploded() slice.setLabelVisible() self.chart = QtCharts.QChart() self.chart.addSeries(self.series) chartView = QtCharts.QChartView(self.chart) screenSize = QGuiApplication.primaryScreen().geometry().size() chartView.resize(screenSize / 2) chartView.show() QTimer.singleShot(500, self.app.quit) self.app.exec_()
def plot_data(self): # Get table information series = QtCharts.QPieSeries() number = dict() for i in range(self.table.rowCount()): if str(self.table.item(i, 1).text()) in number: number[str(self.table.item(i, 1).text())] = \ number[str(self.table.item(i, 1).text())] + float(self.table.item(i, 2).text()) else: number[str(self.table.item(i, 1).text())] = float( self.table.item(i, 2).text()) for i in number: text = "第" + str(i) + "学期" series.append(text, number[str(i)]) chart = QtCharts.QChart() chart.addSeries(series) chart.legend().setAlignment(Qt.AlignLeft) self.chart_view.setChart(chart)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('Memory Usage') memoryUsage = getMemoryUsage() if len(memoryUsage) > 5: memoryUsage = memoryUsage[0:4] self.series = QtCharts.QPieSeries() for item in memoryUsage: self.series.append(item[0], item[1]); slice = self.series.slices()[0] slice.setExploded(); slice.setLabelVisible(); self.chart = QtCharts.QChart() self.chart.addSeries(self.series); self.chartView = QtCharts.QChartView(self.chart) self.setCentralWidget(self.chartView)
def setup_donuts(self): for i in range(self.donut_count): donut = QtCharts.QPieSeries() slccount = randrange(3, 6) for j in range(slccount): value = randrange(100, 200) slc = QtCharts.QPieSlice(str(value), value) slc.setLabelVisible(True) slc.setLabelColor(Qt.white) slc.setLabelPosition(QtCharts.QPieSlice.LabelInsideTangential) # Connection using an extra parameter for the slot slc.hovered[bool].connect(partial(self.explode_slice, slc=slc)) donut.append(slc) size = (self.max_size - self.min_size) / self.donut_count donut.setHoleSize(self.min_size + i * size) donut.setPieSize(self.min_size + (i + 1) * size) self.donuts.append(donut) self.chart_view.chart().addSeries(donut)
from PySide2.QtGui import (QColor, QPainter, QPainterPath, QImage, QPen) from PySide2.QtWidgets import (QApplication, QMainWindow) from PySide2.QtCharts import QtCharts import math import ddv.csv if __name__ == "__main__": app = QApplication(sys.argv) data = ddv.csv.getPieChartData("refugees-by-asylum.csv") series = QtCharts.QPieSeries() sliceList = list(map(lambda nv: QtCharts.QPieSlice(nv[0], nv[1]), zip(data[0], data[1]))) #s1 = QtCharts.QPieSlice("Jane", 1) # s2 = QtCharts.QPieSlice("Doe", 2) series.append(sliceList) #series.append("Jane", 1) #series.append("Joe", 2) #series.append("Andy", 3) #series.append("Barbara", 4) #series.append("Axel", 5) #slc = series.slices()[1]
# hide markers from main series marker.setVisible(False) else: # modify markers from breakdown series marker.setLabel("{} {:.2f}%".format( marker.slice().label(), marker.slice().percentage() * 100, 0)) marker.setFont(QFont("Arial", 8)) if __name__ == "__main__": app = QApplication(sys.argv) # Graph is based on data of: # 'Total consumption of energy increased by 10 per cent in 2010' # Statistics Finland, 13 December 2011 # http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html series1 = QtCharts.QPieSeries() series1.setName("Fossil fuels") series1.append("Oil", 353295) series1.append("Coal", 188500) series1.append("Natural gas", 148680) series1.append("Peat", 94545) series2 = QtCharts.QPieSeries() series2.setName("Renewables") series2.append("Wood fuels", 319663) series2.append("Hydro power", 45875) series2.append("Wind power", 1060) series3 = QtCharts.QPieSeries() series3.setName("Others") series3.append("Nuclear energy", 238789)