def __init__(self): super().__init__() # Create chart chart = qtch.QChart(title=self.chart_title) self.setChart(chart) # Create series series = qtch.QBarSeries() chart.addSeries(series) # add bar sets bar_set = qtch.QBarSet('Percent Used') series.append(bar_set) # Get the data partitions = [] for part in psutil.disk_partitions(): if 'rw' in part.opts.split(','): partitions.append(part.device) usage = psutil.disk_usage(part.mountpoint).percent bar_set.append(usage) # Create Axis x_axis = qtch.QBarCategoryAxis() x_axis.append(partitions) chart.setAxisX(x_axis) series.attachAxis(x_axis) y_axis = qtch.QValueAxis() y_axis.setRange(0, 100) chart.setAxisY(y_axis) series.attachAxis(y_axis) # Add labels series.setLabelsVisible(True)
def __init__(self, parent): super().__init__() self.chart = qtch.QChart() self.setChart(self.chart) self.series = qtch.QBarSeries() self.series.setBarWidth(1) self.chart.addSeries(self.series) self.chart.legend().setVisible(False) self.chart.setContentsMargins(-10, -10, -10, -10) self.bar_set = qtch.QBarSet('') self.series.append(self.bar_set) self.bar_set.append(20) self.x_axis = qtch.QBarCategoryAxis() self.x_axis.setVisible(False) self.chart.setAxisX(self.x_axis) self.series.attachAxis(self.x_axis) self.y_axis = qtch.QValueAxis() self.y_axis.setRange(0, 100) self.y_axis.setTickCount(5) self.y_axis.setVisible(False) self.chart.setAxisY(self.y_axis) self.series.attachAxis(self.y_axis) self.series.setLabelsVisible(True) self.chart.layout().setContentsMargins(0, 0, 0, 0) self.chart.setTheme(qtch.QChart.ChartThemeDark) self.setMinimumSize(10, 50) self.setParent(parent)
def createChart( self ): # function to create a barchart similar to a time series, with each bar showing each year 1 - 10 payback value tech = self.Tech.currentText() series = QtChart.QBarSeries() chart = QtChart.QChart() axis = QtChart.QBarCategoryAxis(chart) categories = [ cat for cat in self.data.columns.values.tolist() if 'year' in cat ] set0 = QtChart.QBarSet('Payback') list0 = list() for cat in categories: list0.append(self.data.at[tech, cat]) set0.append(list0) series.append(set0) #list0.clear() #roicategories = [cat for cat in self.data.columns.values.tolist() if 'roi' in cat] #set1 = QtChart.QBarSet('ROI') #for cat in roicategories: #list0.append(self.data.at[tech, cat]) #set1.append(list0) #series.append(set1) series.setLabelsVisible() chart.addSeries(series) axis.append(categories) chart.createDefaultAxes() chart.setAxisX(axis, series) self.chartView.setChart(chart)
def __init__(self): super(BarStackChart, self).__init__() self.chart = QtChart.QChart() self.chart.setAnimationOptions(QtChart.QChart.SeriesAnimations) # 动态渲染 self.x_category = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] series_names = ['视频广告', '直接访问', '搜索引擎'] series = QtChart.QBarSeries() for name in series_names: bar = QtChart.QBarSet(name) for _ in range(len(self.x_category)): bar.append(random.randint(1, 101)) series.append(bar) # 鼠标悬停信号 bar.hovered.connect(self.bar_hovered) self.chart.addSeries(series) self.chart.createDefaultAxes() # 设置x轴 axis_x = QtChart.QBarCategoryAxis() axis_x.append(self.x_category) self.chart.setAxisX(axis_x, series) # 设置图例 legend = self.chart.legend() legend.setCursor(Qt.PointingHandCursor) # 鼠标悬停图例为手形 for marker in legend.markers(): # 点击事件 marker.clicked.connect(self.legend_clicked) # 悬停事件 marker.hovered.connect(self.legend_hovered) self.setChart(self.chart)
def __init__(self, zones, widget, unit_system): """Create a histogram.""" series = QtChart.QBarSeries() bar_set = QtChart.QBarSet("", series) series.append(bar_set) series.setBarWidth(1) super().__init__([series], widget, unit_system) self.set_zones(zones)
def showBewertungsScreen(self, bewertungen, maxWert): # Andere Fenster schließen self.LoginWindow.close() self.VorlesungWindow.close() # Vorlesungsfenster erstellen self.BewertungsWindow.setMinimumHeight(480) self.BewertungsWindow.setMinimumWidth(800) self.BewertungsWindow.showFullScreen() #Layout festlegen layout = QtWidgets.QGridLayout() #Sets erstellen (unterteilt nach Noten) self.set = QtChart.QBarSet('Gut') self.set1 = QtChart.QBarSet('Okay') self.set2 = QtChart.QBarSet('Zu Langsam') self.set3 = QtChart.QBarSet('Zu Schnell') self.set4 = QtChart.QBarSet('Zu Kompliziert') self.set.append(bewertungen[0]) self.set1.append(bewertungen[1]) self.set2.append(bewertungen[2]) self.set3.append(bewertungen[3]) self.set4.append(bewertungen[4]) #Einzelne Graphen erstellen und mit Sets verknüpfen self.series = QtChart.QBarSeries() self.series.append(self.set) self.series.append(self.set1) self.series.append(self.set2) self.series.append(self.set3) self.series.append(self.set4) #Chart initialiseren und Start Animation festlegen self.chart = QtChart.QChart() self.chart.addSeries(self.series) self.chart.setTitle("Bewertungen") self.chart.setAnimationOptions(QtChart.QChart.SeriesAnimations) #Achsen erstellen und formatieren achseX = QtChart.QBarCategoryAxis() achseY = QtChart.QValueAxis() achseY.setRange(0, maxWert) #Ansicht zusammenstellen und anzeigen self.chart.addAxis(achseX, QtCore.Qt.AlignBottom) self.chart.addAxis(achseY, QtCore.Qt.AlignLeft) self.chart.legend().setVisible(True) self.chart.legend().setAlignment(QtCore.Qt.AlignBottom) chartView = QtChart.QChartView(self.chart) layout.addWidget(chartView) self.BewertungsWindow.setLayout(layout) self.BewertungsWindow.show() self.logikReThread = LogikRestart() self.logikReThread.signalRestart.connect(self.showLoginScreen) self.logikReThread.start()
def display_color_data(self, arr): series = QtChart.QBarSeries() for name, c, col in zip(self.color_names, self.color_reference, arr): s = QtChart.QBarSet(name) s << col s.setColor(QtGui.QColor(c[0], c[1], c[2])) series.append(s) chart = QtChart.QChart() chart.addSeries(series) chart.setTitle("Color distribution") chart.legend() axis = QtChart.QValueAxis() axis.setRange(0, max(arr)) chart.addAxis(axis, QtCore.Qt.AlignLeft) series.attachAxis(axis) self.setChart(chart)
def showHistogram(self, dataChart): series = QtChart.QBarSeries() series.append(dataChart) chart = QtChart.QChart() chart.addSeries(series) chart.setTitle("Histogram") chart.setAnimationOptions(QtChart.QChart.SeriesAnimations) chart.setTheme(QtChart.QChart.ChartThemeBlueCerulean) axis = QtChart.QValueAxis() chart.createDefaultAxes() chart.setAxisX(axis, series) chart.axisY(series) chart.legend().setVisible(True) chart.legend().setAlignment(QtCore.Qt.AlignBottom) self.chartview.setChart(chart) self.chartview.setRenderHint(QtGui.QPainter.Antialiasing)
def __init__(self): super().__init__() chart = qtch.QChart(title=self.chart_title) self.setChart(chart) series = qtch.QBarSeries() chart.addSeries(series) bar_set = qtch.QBarSet('Percent Used') series.append(bar_set) partitions = [] bar_set.append(20) x_axis = qtch.QBarCategoryAxis() x_axis.append(partitions) chart.setAxisX(x_axis) series.attachAxis(x_axis) y_axis = qtch.QValueAxis() y_axis.setRange(0, 100) chart.setAxisY(y_axis) series.attachAxis(y_axis) series.setLabelsVisible(True)
def add_chart(self, weights, colors, type="bar"): if not hasattr(self, 'axisX'): self.axisX = QtChart.QBarCategoryAxis() for n in range(len(weights)): self.axisX.append("<span style=\"color: " + colors[n] + ";\">{}</span>".format(n + 1)) self.axisY = QtChart.QValueAxis() self.axisX.setTitleText("Components") self.axisY.setTitleText("Weight (%)") self.axisY.setRange(0, 100) self.axisX.setLabelsFont( QtGui.QFont(self.fontname, self.fontsize, 57)) self.axisX.setTitleFont( QtGui.QFont(self.fontname, self.fontsize, 57)) self.axisY.setLabelsFont( QtGui.QFont(self.fontname, self.fontsize, 57)) self.axisY.setTitleFont( QtGui.QFont(self.fontname, self.fontsize, 57)) self.barChart.addAxis(self.axisX, QtCore.Qt.AlignBottom) self.barChart.addAxis(self.axisY, QtCore.Qt.AlignLeft) elif len(weights) != self.ncomp: self.axisX.clear() for n in range(len(weights)): self.axisX.append("<span style=\"color: " + colors[n] + ";\">{}</span>".format(n + 1)) self.ncomp = len(weights) self.barChart.removeAllSeries() series = QtChart.QBarSeries() barset = QtChart.QBarSet("Weight") for n in range(self.ncomp): barset.append(weights[n] * 100) series.append(barset) self.barChart.addSeries(series) series.attachAxis(self.axisX) series.attachAxis(self.axisY) self.CHART_IS_PRESENT = True
def __init__(self): super().__init__() self.setLayout(qtw.QVBoxLayout()) grpbxwidgt = qtw.QGroupBox() grpbxwidgt.setTitle("Visualization of Data") grpbxwidgt.setLayout(qtw.QVBoxLayout()) # BAR GRAPH self.series = qtch.QBarSeries() self.chart = qtch.QChart() self.chart.addSeries(self.series) self.chart.setTitle("<h5>Daily Income & Expense</h5>") self.chart.setAnimationOptions(qtch.QChart.SeriesAnimations) self.axis = qtch.QBarCategoryAxis() self.chart.createDefaultAxes() self.chart.setAxisX(self.axis,self.series) self.chart.axisY(self.series).setRange(0,10000) self.chart.axisY(self.series).setTitleText("Money (LKR)") self.chart.legend().setVisible(True) self.chart.legend().setAlignment(qtc.Qt.AlignBottom) self.chartview = qtch.QChartView(self.chart) self.chartview.setRenderHint(qtg.QPainter.Antialiasing) # PIE CHART self.pieseries = qtch.QPieSeries() self.piechart = qtch.QChart() self.piechart.addSeries(self.pieseries) self.piechart.setTitle("Item's Sold and Remaining") self.piechart.setAnimationOptions(qtch.QChart.AllAnimations) self.piechartview = qtch.QChartView(self.piechart) self.piechartview.setRenderHint(qtg.QPainter.Antialiasing) # selection widget product_widget = qtw.QGroupBox() product_widget.setTitle("Item Selection") product_layout = qtw.QHBoxLayout() product_widget.setLayout(product_layout) pushbutton = qtw.QPushButton("Filter",clicked = self.update_piechart) self.combobox = qtw.QComboBox(currentText = "select an item") self.c = ComboboxModel() #comboxlist model self.combobox.setModel(self.c.model) product_layout.addWidget(self.combobox) product_layout.addWidget(pushbutton) # calendar widget calendar_widget = qtw.QGroupBox() calendar_widget.setTitle("Date Selection") calendar_layout = qtw.QHBoxLayout() calendar_widget.setLayout(calendar_layout) # calculating the current month and current year current_month = int(datetime.now().month) current_year = int(datetime.now().year) date = qtc.QDate(current_year,current_month,1) self.to_date = qtw.QDateEdit() to_label = qtw.QLabel("To") self.to_date.setCalendarPopup(True) self.to_date.setDate(date) self.from_date = qtw.QDateEdit() from_label = qtw.QLabel("From") self.from_date.setCalendarPopup(True) self.from_date.setDate(qtc.QDate.currentDate()) pushbtn = qtw.QPushButton("Filter",clicked =self.update_data) calendar_layout.addWidget(to_label) calendar_layout.addWidget(self.to_date) calendar_layout.addWidget(from_label) calendar_layout.addWidget(self.from_date) calendar_layout.addWidget(pushbtn) # end of calendar widget self.chartview.setSizePolicy(qtw.QSizePolicy.Minimum,qtw.QSizePolicy.Expanding) self.piechartview.setSizePolicy(qtw.QSizePolicy.Minimum,qtw.QSizePolicy.Expanding) grpbxwidgt.layout().addWidget(calendar_widget) grpbxwidgt.layout().addWidget(self.chartview) grpbxwidgt.layout().addWidget(product_widget) grpbxwidgt.layout().addWidget(self.piechartview) self.layout().addWidget(grpbxwidgt)
def showChart( self ): # function to show the chart of data of user selected tech and attribute on QChartView file1 = self.techselector1.currentText() current_building1, current_tech1 = file1.split(' - ') current_buildingI1, current_buildingI2, current_techI1, current_techI2 = 0, 0, 0, 0 for index, file in enumerate(self.fl): if file.building_name == current_building1: current_buildingI1 = index file2 = self.techselector2.currentText() current_building2, current_tech2 = file2.split(' - ') for index, file in enumerate(self.fl): if file.building_name == current_building2: current_buildingI2 = index att = self.attselector.currentText( ) # assign user selected texts from drop down lists to parameters series = QtChart.QBarSeries( ) # the lines below creates the bar chart with the 2 tech selected as the categories (x-axis) with data from chart = QtChart.QChart( ) # filelist dfSumDiff (summary of sum of each attributes in all dataframes) axis = QtChart.QBarCategoryAxis(chart) categories = [file1, file2] if att != 'Sum': set0 = QtChart.QBarSet( att ) # use only the user-specified attribute sum value attained from dataframe as one set of bars set0.append([ self.fl[current_buildingI1].dfSumDiff.at[file1, att], self.fl[current_buildingI2].dfSumDiff.at[file2, att] ]) series.append(set0) else: for cat in self.cl.cl: # add different set of bars for different category total set0 = QtChart.QBarSet(att + '(' + cat.name + ')') df_temp = self.fl[current_buildingI1].dfSumDiff[ self.fl[current_buildingI1].dfSumDiff.columns.intersection( cat.members)] if current_buildingI1 != current_buildingI2: df_temp = df_temp.append( self.fl[current_buildingI2].dfSumDiff[self.fl[ current_buildingI2].dfSumDiff.columns.intersection( cat.members)]) if cat.name != 'Cooling load': df_temp = df_temp.T.append(df_temp.loc[:, [ col for col in df_temp.columns if 'DX' not in col ]].sum(axis='columns').to_frame( ).T) # add the sum of the category as a new column else: df_temp = df_temp.T.append(df_temp.loc[:, [ 'Ap Sys chillers load (kWh)', 'ApHVAC chillers load (kWh)' ]].sum(axis='columns').to_frame().T) df_temp.rename({0: 'Sum'}, axis='index', inplace=True) df_temp = df_temp.T set0.append( [df_temp.at[file1, 'Sum'], df_temp.at[file2, 'Sum']]) series.append(set0) series.setLabelsVisible() chart.addSeries(series) axis.append(categories) chart.createDefaultAxes() chart.setAxisX(axis, series) self.chartView.setChart(chart)