def __init__(self, parent=None): super().__init__(parent) self.m_model = CustomTableModel() tableView = QTableView() tableView.setModel(self.m_model) tableView.setMinimumWidth(300) tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) tableView.verticalHeader().setSectionResizeMode(QHeaderView.Stretch) self.m_model.setParent(tableView) chart = QChart() chart.setAnimationOptions(QChart.AllAnimations) series = QBarSeries() first = 3 count = 5 mapper = QVBarModelMapper(self) mapper.setFirstBarSetColumn(1) mapper.setLastBarSetColumn(4) mapper.setFirstRow(first) mapper.setRowCount(count) mapper.setSeries(series) mapper.setModel(self.m_model) chart.addSeries(series) seriesColorHex = "#000000" barsets = series.barSets() for i, barset in enumerate(barsets): seriesColorHex = barset.brush().color().name() self.m_model.addMapping( seriesColorHex, QRect(1 + i, first, 1, barset.count()) ) categories = ("April", "May", "June", "July", "August") axisX = QBarCategoryAxis() axisX.append(categories) chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisY = QValueAxis() chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) chartView.setMinimumSize(640, 480) mainLayout = QGridLayout(self) mainLayout.addWidget(tableView, 1, 0) mainLayout.addWidget(chartView, 1, 1) mainLayout.setColumnStretch(1, 1) mainLayout.setColumnStretch(0, 0)
class StatsTab(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.seriesmap = {} # map items to series # create widgets self.stat_list = QListWidget(self) chart = QChart() self.chart_view = QChartView(chart, self) for i in range(30): series = QLineSeries(self) for j in range(20): series.append(j, i * 3 + j) item = QListWidgetItem() item.setData(Qt.DisplayRole, str(i)) item.setData(Qt.UserRole, i) if i < 10: item.setData(Qt.CheckStateRole, Qt.Checked) else: item.setData(Qt.CheckStateRole, Qt.Unchecked) series.hide() chart.addSeries(series) self.stat_list.addItem(item) self.seriesmap[i] = series # create layout layout = QHBoxLayout(self) layout.addWidget(self.stat_list) layout.addWidget(self.chart_view) layout.setStretchFactor(self.chart_view, 3) # configure widgets chart.legend().hide() chart.createDefaultAxes() chart.setTitle("Daily aggregated stats of your school") self.chart_view.setRenderHint(QPainter.Antialiasing) self.retranslateUi() # connect signals self.stat_list.itemClicked.connect(self.on_stat_clicked) def retranslateUi(self): chart = self.chart_view.chart() chart.setTitle( QApplication.translate("StatsTab", "Daily aggregated stats of your school")) @pyqtSlot(QListWidgetItem) def on_stat_clicked(self, item): key = item.data(Qt.UserRole) series = self.seriesmap[key] series.setVisible(not series.isVisible())
def afterDelay(self): # print("in after delay bar") min_num, max_num = 0, 100 max_count = 0 total_stopped_after_delay = [] count = [0] * (int(max_num) + 1) # choose the largest num as length of count try: total_stopped_after_delay = self.tm.total_stopped_after_delay max_num = max(total_stopped_after_delay) count = [0] * (int(max_num) + 1) # choose the largest num as length of count for num in total_stopped_after_delay: count[int(num)] += 1 # update every number's count max_count = max(count) except (AttributeError, ValueError): self.statusbar.showMessage('Data not ready') setBar = QBarSet('Stop Time Occurrence') setBar.append(count) brush = QBrush(QColor(0xA6E22E)) # Green pen = QPen(QColor(0xA6E22E)) # Green pen.setWidth(2) setBar.setPen(pen) setBar.setBrush(brush) series = QBarSeries() series.append(setBar) chart = QChart() font = QFont() font.setPixelSize(18) chart.setTitleFont(font) chart.setTitle('Stop time Occurrence (after)') chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) axisX = QValueAxis() axisX.setRange(min_num, max_num+20) chart.setAxisX(axisX, series) axisY = QValueAxis() axisY.setRange(0, max_count+20) chart.setAxisY(axisY, series) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) # MainWindow.setCentralWidget(chartView) return chartView
def initUI(self): #Panel valores -métodos ejecutados self.color_fondo = self.lista_color_fondo() self.animacion_grafica = self.lista_animacion() self.leyenda_grafica = self.lista_leyenda() self.marcador_grafica = self.lista_marcadores() self.posicion_grafica = self.lista_posicion_leyenda() self.posicion_grafica = self.lista_posicion_leyenda() self.mostrar_ocultar_leyenda = QCheckBox("Mostrar etiqueta") #Panel- menú-Horizontal panel_widget = QHBoxLayout() panel_widget.addWidget(QLabel("Tema")) panel_widget.addWidget(self.color_fondo) panel_widget.addWidget(QLabel("Animación")) panel_widget.addWidget(self.animacion_grafica) panel_widget.addWidget(QLabel("Leyenda")) panel_widget.addWidget(self.leyenda_grafica) panel_widget.addWidget(QLabel("Marcador")) panel_widget.addWidget(self.marcador_grafica) panel_widget.addWidget(QLabel("Ubicación")) panel_widget.addWidget(self.posicion_grafica) panel_widget.addWidget(self.mostrar_ocultar_leyenda) panel_widget.addStretch() #Ajustar widgets #Contedor -Gráfica contenedor_grafica = QChartView(self.grafica_circular()) contenedor_grafica.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) contenedor_grafica.setRenderHint(QPainter.Antialiasing, True) self.grafica = contenedor_grafica #Layout layout = QGridLayout() layout.addLayout(panel_widget, 1, 0, 1, 0) #Agregar un layout: HBox.. layout.addWidget(contenedor_grafica, 2, 0, 4, 0) #Agregar un wigget self.setLayout(layout) #Funciones self.color_fondo.currentIndexChanged.connect(self.update_initUI) self.animacion_grafica.currentIndexChanged.connect(self.update_initUI) self.leyenda_grafica.currentIndexChanged.connect(self.update_initUI) self.marcador_grafica.currentIndexChanged.connect(self.update_initUI) self.posicion_grafica.currentIndexChanged.connect(self.update_initUI) self.mostrar_ocultar_leyenda.toggled.connect(self.update_initUI) #Valor predeterminado-mostrar leyenda gráfica self.mostrar_ocultar_leyenda.setChecked(True) self.update_initUI()
class WindowStatic(QWidget): def __init__(self, window: WindowCinemas = None, title: str = '', base: list = None) -> None: super().__init__() self.title = title self.window = window.static self.base = base self._init_ui() def _init_chart(self) -> None: series = QBarSeries() axis_x = QBarCategoryAxis() axis_y = QValueAxis() data_set = defaultdict(int) for title, money in self.base: data_set[title] += money for title, money in data_set.items(): bar = QBarSet(title) axis_x.append(title) bar.append(money) series.append(bar) # self.chart = QChart() self.chart.addSeries(series) self.chart.setAnimationOptions(QChart.SeriesAnimations) # series.attachAxis(axis_x) self.chart.addAxis(axis_x, Qt.AlignBottom) axis_y.setRange(0, max(data_set.values())) axis_y.setTickCount(11) self.chart.addAxis(axis_y, Qt.AlignLeft) series.attachAxis(axis_y) # self.chart.legend().setVisible(True) self.chart.legend().setAlignment(Qt.AlignBottom) def _init_ui(self) -> None: self.window.resize(1000, 900) self._init_chart() self.chartView = QChartView(self.chart) self.chartView.setRenderHint(QPainter.Antialiasing) self.label_title = QLabel(self.title) # self.label_title.setFont(QFont('MS Shell Dlg 2', 20)) # self.label_title.setAlignment(Qt.AlignHCenter | Qt.AlignHCenter) # self.layout = QVBoxLayout(self, spacing=0) self.layout.setContentsMargins(10, 0, 10, 0) # self.layout.addWidget(self.label_title) self.layout.addWidget(self.chartView)
def __init__(self, config: Config, chart_view: QChartView) -> None: self.chart_view = chart_view self.config = config self.initialized = False chart_view.setRenderHint(QPainter.Antialiasing) self.chart: QChart = chart_view.chart() legend: QLegend = self.chart.legend() legend.hide() self.chart_view.repaint()
class Window(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("PyQtChart Demo") self.setGeometry(500, 275, 650, 500) self.show() self.createLineChart() def createLineChart(self): self.font = QFont("Arial") self.font.setPixelSize(16) self.font.setBold(True) self.pen = QPen(QColor(0, 153, 0)) self.pen.setWidth(3) self.series = QLineSeries(self) self.series.setPen(self.pen) self.x = np.arange(0, 2 * np.pi, 0.01) for i in self.x: self.series.append(i, np.sin(i)) self.chart = QChart() self.chart.addSeries(self.series) self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setTitleFont(self.font) self.chart.setTitleBrush(QBrush(Qt.blue)) self.chart.setTitle("Line Chart Demo") self.chart.legend().setVisible(True) self.chart.legend().setAlignment(Qt.AlignBottom) self.chartview = QChartView(self.chart) self.chartview.setRenderHint(QPainter.Antialiasing) self.axisX = QValueAxis() self.axisX.setRange(0, 2 * np.pi) self.axisX.setTickCount(6) self.axisX.setLabelFormat("%.1f") self.axisX.setTitleText("x") self.axisY = QValueAxis() self.axisY.setRange(0, 100) self.axisY.setLabelFormat("%d") self.axisY.setTitleText("sin(x)") self.chart.addAxis(self.axisX, Qt.AlignBottom) self.chart.addAxis(self.axisY, Qt.AlignLeft) self.setCentralWidget(self.chartview)
def beforeDelayDistribution(self): min_num, max_num = 0, 100 max_count = 0 total_stopped_time = [] try: total_stopped_time = self.tm.total_stopped_time max_num = max(total_stopped_time) except AttributeError: self.statusbar.showMessage('Data not ready') count = total_stopped_time # count = [0] * (int(max_num) + 1) # choose the largest num as length of count # for num in total_stopped_time: # count[int(num)] += 1 # update every number's count max_count = max(count) setBar = QBarSet('stop time') setBar.append(count) brush = QBrush(QColor(0x57B1FD)) pen = QPen(QColor(0x57B1FD)) pen.setWidth(2) setBar.setPen(pen) setBar.setBrush(brush) series = QBarSeries() series.append(setBar) chart = QChart() font = QFont() font.setPixelSize(18) chart.setTitleFont(font) chart.setTitle('Stop time Distribution (before)') chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) axisX = QValueAxis() axisX.setRange(min_num, max_num + 20) chart.setAxisX(axisX, series) axisY = QValueAxis() axisY.setRange(0, max_count + 20) chart.setAxisY(axisY, series) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) # MainWindow.setCentralWidget(chartView) return chartView
def createSummaryBar(self): # self.dp.dfinal series = QPieSeries() labelfont = QFont() labelfont.setPixelSize(11) try: series.append("Linked", len(self.linked.index)) series.append("Unlinked", len(self.unlinked.index)) # slices = QPieSlice() slices1 = series.slices()[1] slices1.setExploded() slices1.setLabelVisible() slices1.setPen(QPen(QColor(0x57B1FD), 2)) slices1.setBrush(QBrush(QColor(0xfdb157))) slices1.setLabelPosition(QPieSlice.LabelOutside) slices1.setLabel( ("{0} {1:.2f}%").format("Unlinked", 100 * slices1.percentage())) slices1.setLabelFont(labelfont) # slices.setPen(QPen(Qt.darkGreen, 2)) # slices.setBrush(QBrush(QColor(0xfdb157))) except AttributeError: self.statusbar.showMessage('Data not ready') series.append("Total", 1) slices = series.slices()[0] slices.setBrush(QBrush(QColor(0x57B1FD))) # slices.setLabel(("%1%").format(100*slices.percentage(), 0, 'f', 1)) # slices.setLabelPosition(QPieSlice.LabelInsideHorizontal) if len(series.slices() ) == 2: # display "linked" label only at data was processed slices.setLabelVisible() slices.setLabel(("{0} {1:.2f}%").format("Linked", 100 * slices.percentage())) slices.setLabelFont(labelfont) chart = QChart() font = QFont() font.setPixelSize(18) chart.setTitleFont(font) chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("Total") chart.legend().hide() chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) return chartView
def main(): import sys app = QApplication(sys.argv) acmeSeries = QBoxPlotSeries() acmeSeries.setName("Acme Ltd") boxWhiskSeries = QBoxPlotSeries() boxWhiskSeries.setName("BoxWhisk Inc") acmeData = QFile(":acme") if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) dataReader = BoxDataReader(acmeData) while not dataReader.atEnd(): _set = dataReader.readBox() if _set is not None: acmeSeries.append(_set) boxwhiskData = QFile(":boxwhisk") if not boxwhiskData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) dataReader.readFile(boxwhiskData) while not dataReader.atEnd(): _set = dataReader.readBox() if _set is not None: boxWhiskSeries.append(_set) chart = QChart() chart.addSeries(acmeSeries) chart.addSeries(boxWhiskSeries) chart.setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012") chart.setAnimationOptions(QChart.SeriesAnimations) chart.createDefaultAxes() chart.axes(Qt.Vertical)[0].setMin(15.0) chart.axes(Qt.Vertical)[0].setMax(34.0) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(800, 600) window.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) chart = DynamicSpline() chart.setTitle("Dynamic spline chart") chart.legend().hide() chart.setAnimationOptions(QChart.AllAnimations) view = QChartView(chart) view.setRenderHint(QPainter.Antialiasing) view.resize(1000, 500) view.show() sys.exit(app.exec_())
def createUnlinkedBar(self): pushed_bin = 0 slipping_bin = 0 others = 0 try: total_bins = self.total_bins scanner_linked_rfid = self.scanner_linked_rfid unlinked_bins = total_bins - scanner_linked_rfid slipping_bin = len(self.slipping.index) pushed_bin = len(self.pushed.index) others = unlinked_bins-pushed_bin-slipping_bin except AttributeError: self.statusbar.showMessage('Data not ready') series = QPieSeries() series.setHoleSize(0.35) series.append("Pushed", pushed_bin) series.append("Slipping", slipping_bin) series.append("Others", others) slices = series.slices()[0] slices.setLabelVisible() slices.setLabel("{0} {1:.2f}".format("Pushed", 100*slices.percentage())) slices1 = series.slices()[1] slices1.setLabelVisible() slices1.setLabel("{0} {1:.2f}".format("Slipping", 100*slices1.percentage())) # set exploded slice if pushed_bin > slipping_bin: slices.setExploded() else: slices1.setExploded() slices2 = series.slices()[2] slices2.setLabelVisible() slices2.setLabel("{0} {1:.2f}".format("Others", 100*slices2.percentage())) chart = QChart() chart.setTheme(QChart.ChartThemeBlueCerulean) chart.legend().hide() font = QFont() font.setPixelSize(16) chart.setTitleFont(font) chart.setTitle("Unlinked Details") chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) return chartView
def main(): import sys app = QApplication(sys.argv) set0 = QBarSet("Jane") set1 = QBarSet("John") set2 = QBarSet("Axel") set3 = QBarSet("Mary") set4 = QBarSet("Samantha") set0 << 1 << 2 << 3 << 4 << 5 << 6 set1 << 5 << 0 << 0 << 4 << 0 << 7 set2 << 3 << 5 << 8 << 13 << 8 << 5 set3 << 5 << 6 << 7 << 3 << 4 << 5 set4 << 9 << 7 << 5 << 3 << 1 << 2 series = QBarSeries() series.append(set0) series.append(set1) series.append(set2) series.append(set3) series.append(set4) chart = QChart() chart.addSeries(series) chart.setTitle("Simple barchart example") chart.setAnimationOptions(QChart.SeriesAnimations) categories = ("Jan", "Feb", "Mar", "Apr", "May", "Jun") axisX = QBarCategoryAxis() axisX.append(categories) chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisY = QValueAxis() axisY.setRange(0, 15) chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(420, 300) window.show() sys.exit(app.exec_())
def create_chart(self): series = self.load_slices() chart = QChart() chart.legend().hide() chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("File extensions") chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) self.layout.addWidget(chartview) self.layout.addWidget(self.text_label)
def main(): import sys a = QApplication(sys.argv) acmeSeries = QCandlestickSeries() acmeSeries.setName("Acme Ltd") acmeSeries.setIncreasingColor(QColor(Qt.green)) acmeSeries.setDecreasingColor(QColor(Qt.red)) acmeData = QFile(":acme") if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) categories = [] dataReader = CandlestickDataReader(acmeData) while not dataReader.atEnd(): _set = dataReader.readCandlestickSet() if _set is not None: acmeSeries.append(_set) categories.append( QDateTime.fromMSecsSinceEpoch(int( _set.timestamp())).toString("dd")) chart = QChart() chart.addSeries(acmeSeries) chart.setTitle("Acme Ltd Historical Data (July 2015)") chart.setAnimationOptions(QChart.SeriesAnimations) chart.createDefaultAxes() axisX = chart.axes(Qt.Horizontal)[0] axisX.setCategories(categories) axisY = chart.axes(Qt.Vertical)[0] axisY.setMax(axisY.max() * 1.01) axisY.setMin(axisY.min() * 0.99) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(800, 600) window.show() sys.exit(a.exec_())
def createChart(self, title, series): chart = QChart() chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle(title) #sslice.setLabel("{:.1f}%".format(100 * slice.percentage())) chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) #setChart(chartview) self.ui.pieChart_container.addWidget(chartview)
def setCoresGragh(self): self.chart = DynamicSpline(0) self.chart.setTitle("Core 1") view = QChartView(self.chart) view.setRenderHint(QPainter.Antialiasing) # 抗锯齿 view.show() self.verticalLayout.addWidget(view) self.chart2 = DynamicSpline(1,QColor(39, 155, 218)) self.chart2.setTitle("Core 2") view2 = QChartView(self.chart2) view2.setRenderHint(QPainter.Antialiasing) # 抗锯齿 view2.show() self.verticalLayout_2.addWidget(view2) self.chart3 = DynamicSpline(2,QColor(241, 168, 56)) self.chart3.setTitle("Core 3") view3 = QChartView(self.chart3) view3.setRenderHint(QPainter.Antialiasing) # 抗锯齿 view3.show() self.verticalLayout_3.addWidget(view3) self.chart4 = DynamicSpline(3,QColor(241, 56, 129)) self.chart4.setTitle("Core 4") view4 = QChartView(self.chart4) view4.setRenderHint(QPainter.Antialiasing) # 抗锯齿 self.verticalLayout_4.addWidget(view4)
def beforeDelayDistribution(self): min_num, max_num = 0, 100 max_count = 0 total_stopped_time = [] count = [0] try: total_stopped_time = self.tm.total_stopped_time max_num = len(total_stopped_time) # change from max() to len() 2/12 11:11 count = total_stopped_time max_count = max(count) except (AttributeError, ValueError): self.statusbar.showMessage('Data not ready') setBar = QBarSet('stop time') setBar.append(count) brush = QBrush(QColor(0x57B1FD)) pen = QPen(QColor(0x57B1FD)) pen.setWidth(2) setBar.setPen(pen) setBar.setBrush(brush) series = QBarSeries() series.append(setBar) chart = QChart() font = QFont() font.setPixelSize(18) chart.setTitleFont(font) chart.setTitle('Stop time Distribution (before)') chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) axisX = QValueAxis() axisX.setRange(min_num, max_num) chart.setAxisX(axisX, series) axisY = QValueAxis() axisY.setRange(0, max_count+20) chart.setAxisY(axisY, series) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) # MainWindow.setCentralWidget(chartView) return chartView
class ChartWidget(QWidget): def __init__(self, device, parent=None): super().__init__(parent) self.ch = ChartObject(devices=device) self.view = QChartView(self.ch.chart) self.view.setRenderHint(QPainter.Antialiasing) layout = QVBoxLayout() layout.addWidget(self.view) self.setLayout(layout) self.resize(500, 800) self.color = Qt.black def set_title(self, title): self.ch.chart.setTitle(title)
def make_cake( self ): score_1 = self.players[ 0 ].score score_2 = self.players[ 1 ].score series = QPieSeries() free_score = 120 - score_1 - score_2 series.append( f"{free_score}", free_score ) series.append( f"{score_1}", score_1 ) series.append( f"{score_2}", score_2 ) series.setPieStartAngle( 3 * score_2 ) series.setPieEndAngle( 3 * score_2 + 360 ) slices = series.slices() for slice in slices: slice.setLabelVisible( True ) if slice.angleSpan() < 45: slice.setLabelPosition( QPieSlice.LabelPosition.LabelInsideNormal ) elif slice.angleSpan() < 90: slice.setLabelPosition( QPieSlice.LabelPosition.LabelInsideTangential ) else: slice.setLabelPosition( QPieSlice.LabelPosition.LabelInsideHorizontal ) slice.setLabelColor( QColor( "#00000" ) ) slice.setLabelFont( QFont( "Fira Sans", 60, weight=QFont.Weight.Black ) ) slice.setBorderWidth( 0 ) slices[ 0 ].setLabelPosition( QPieSlice.LabelPosition.LabelInsideHorizontal ) if score_1 < 10: slices[ 1 ].setLabelFont( QFont( "Fira Sans", score_1 * 6, weight=QFont.Weight.Black ) ) if score_2 < 10: slices[ 2 ].setLabelFont( QFont( "Fira Sans", score_2 * 6, weight=QFont.Weight.Black ) ) slices[ 0 ].setLabelColor( QColor( "#FFFFFF" ) ) slices[ 0 ].setColor( remaining_points_color ) slices[ 1 ].setColor( player_1.color ) slices[ 2 ].setColor( player_2.color ) chart = QChart() chart.legend().hide() chart.addSeries( series ) chart.createDefaultAxes() chart.setBackgroundVisible( False ) chart.setContentsMargins( -120, -120, -120, -120 ) chart.layout().setContentsMargins( 0, 0, 0, 0 ) chart_view = QChartView( chart ) chart_view.setRenderHint( QPainter.Antialiasing ) return chart_view
def create_chart(self): # 创建折线视图窗口 modelutil = ModelUtil() dataTable = modelutil.get_score(self.username) chart = QChartView(self) #获取显示器高宽 screeRect = QApplication.desktop().screenGeometry() chart.setGeometry(QtCore.QRect(screeRect)) chart.setRenderHint(QPainter.Antialiasing) # 抗锯齿 chart.raise_() # qfont=QFont() # qfont.setPointSize(34) # qfont.setPixelSize(45) chart._chart = QChart(title="考试成绩折线图") # 创建折线视图 # chart._chart.setFont(qfont) # chart.setStyleSheet( # "QChartView{border:2px}" # "QChartView{border-radius:10px}" # "QChartView{font-family:宋体}" # "QChartView{word-wrap:true}" # "QChartView{font-size:25px}" # "QChartView{padding:2px 2px}") # chart._chart.setFont(qfont) # chart._chart.setBackgroundVisible(visible=False) # 背景色透明 chart._chart.setBackgroundBrush(QBrush(QColor("#FFFFFF"))) # 改变图背景色 # 图形项默认无法接收悬停事件,可以使用QGraphicsItem的setAcceptHoverEvents()函数使图形项可以接收悬停事件。 chart._chart.setAcceptHoverEvents(True) # 4条折线的坐标值 # 执行创建折线的函数 self.create_series(dataTable, chart) chart._chart.createDefaultAxes() # 创建默认的轴 chart._chart.axisY().setTickCount(11) # y1轴设置10个刻度 chart._chart.axisY().setLabelFormat("%d") chart._chart.axisY().setRange(0, 100) # 设置y1轴范围 xnum = len(dataTable[0]) - 1 chart._chart.axisX().setTickCount(xnum) # X轴设置10个刻度 # 执行定义X轴的函数 # self.customAxisX(chart._chart) chart.setChart(chart._chart)
def __init__(self): super().__init__() self.resize(800, 600) set0 = QBarSet('X0') set1 = QBarSet('X1') set2 = QBarSet('X2') set3 = QBarSet('X3') set4 = QBarSet('X4') set0.append([1, 2, 3, 4, 5, 6]) set1.append([5, 0, 0, 4, 0, 7]) set2.append([3, 5, 8, 13, 8, 5]) set3.append([5, 6, 7, 3, 4, 5]) set4.append([9, 7, 5, 3, 1, 2]) series = QHorizontalBarSeries() series.append(set0) series.append(set1) series.append(set2) series.append(set3) series.append(set4) chart = QChart() chart.addSeries(series) chart.setTitle('Horizontal Bar Chart Demo') chart.setAnimationOptions(QChart.SeriesAnimations) months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June') axisY = QBarCategoryAxis() axisY.append(months) chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) axisX = QValueAxis() chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisX.applyNiceNumbers() chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(chartView)
class Chart(QWidget): def __init__(self, chartKey, parent=None): super(Chart, self).__init__(parent) 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("DonutChart Example") self.chart.setTheme(QChart.ChartThemeBlueCerulean) self.chartview = QChartView(self.chart) self.chartview.setRenderHint(QPainter.Antialiasing) def addSeries(self, key): self.chart.removeAllSeries() self.series = QPieSeries() self.series.setHoleSize(0.35) for key, value in sampleData[key].items(): print("adding series", str(key), value) slice_ = QPieSlice(str(key), value) self.series.append(slice_) self.chart.addSeries(self.series) self.series.doubleClicked.connect(self.handle_double_clicked) #Show the update chart with the distribution of the selected slice def handle_double_clicked(self, slice): slice.setExploded() slice.setLabelVisible() if slice.label() in sampleData.keys(): print("slice",slice.label()); self.addSeries(slice.label())
def afterDelayPieChart(self): series = QPieSeries() labelfont = QFont() labelfont.setPixelSize(11) total_running_after_delay, total_stopped_after_delay = [], [] try: total_running_after_delay = self.tm.total_running_after_delay total_stopped_after_delay = self.tm.total_stopped_after_delay # slices.setPen(QPen(Qt.darkGreen, 2)) # slices.setBrush(QBrush(QColor(0xfdb157))) except AttributeError: self.statusbar.showMessage('Data not ready') series.append("Run", sum(total_running_after_delay)) series.append("Stop", sum(total_stopped_after_delay)) # slices = QPieSlice() slices = series.slices()[0] # Run time slice slices.setBrush(QBrush(QColor(0x57B1FD))) # Blue slices.setLabelVisible() # Set label visible slices.setLabel(("{0} {1:.2f}%").format("Run time", 100*slices.percentage())) # Set percentage slices.setLabelFont(labelfont) # Set label font slices1 = series.slices()[1] # Stop time slice slices1.setExploded() # Set stop slice exploded slices1.setLabelVisible() # Set label visible slices1.setPen(QPen(QColor(0x57B1FD), 2)) # Blue slices1.setBrush(QBrush(QColor(0xA6E22E))) # Orange # slices1.setLabelPosition(QPieSlice.LabelOutside) # Set label outside slices1.setLabel(("{0} {1:.2f}%").format("Stop time", 100*slices1.percentage())) # Set percentage slices1.setLabelFont(labelfont) # Set label font chart = QChart() font = QFont() font.setPixelSize(18) chart.setTitleFont(font) chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("Total Time (after)") chart.legend().hide() chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) return chartView
def trigger_stage_4(self): # self.get_column_data() self.content_1.setVisible(False) self.content_2.setVisible(False) self.content_3.setVisible(False) self.content_4.setVisible(True) self.progressBar.setValue(99) self.stage_1.setChecked(False) self.stage_1.setEnabled(False) self.stage_2.setChecked(False) self.stage_2.setEnabled(False) self.stage_3.setChecked(False) self.stage_3.setEnabled(False) self.stage_4.setChecked(True) self.stage_4.setEnabled(True) series = QLineSeries(self) series.append(0, 6) series.append(2, 4) series.append(3, 8) series.append(7, 4) series.append(10, 5) series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2) chart = QChart() # chart.addSeries(series) chart.createDefaultAxes() chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle(self.chosenColumn[0]) # chart.legend().setVisible(True) # chart.legend().setAlignment(Qt.AlignBottom) # chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) self.content_4.layout = QtWidgets.QVBoxLayout(self) self.content_4.layout.addWidget(chartview) # layout = QtGui.QVBoxLayout() # layout.addWidget(self.content_4) # self.setLayout(layout) self.setCentralWidget(chartview)
class ChartArea(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle("Dave Test") self.resize(230, 254) self.show() #QtChart Stuff self.chart = QChart() self.chart.legend().hide() self.view = QChartView(self.chart) self.view.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(self.view)
def _create_revision_count_graph(self): stats = CollectionStats(self.col) categories_labels = list(range(-30, 1, 1)) data = stats.revision_count_stats() data = self._transform_first_column_to_key(data) data = self._add_default_value_for_missing_keys( data, [0, 0, 0, 0, 0], categories_labels) series = QStackedBarSeries(self) setLearning = QBarSet("Learning", self) [setLearning.append(row[0]) for row in data] setYoung = QBarSet("Young", self) [setYoung.append(row[1]) for row in data] setMature = QBarSet("Mature", self) [setMature.append(row[2]) for row in data] setLapse = QBarSet("Lapse", self) [setLapse.append(row[3]) for row in data] setEarly = QBarSet("Early", self) [setEarly.append(row[4]) for row in data] categories = QBarCategoryAxis() categories.setCategories([str(-i) for i in categories_labels]) series.append(setLearning) series.append(setYoung) series.append(setMature) series.append(setLapse) series.append(setEarly) chart = QChart() chart.addSeries(series) chart.createDefaultAxes() chart.setAxisX(categories, series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("Number of cards reviewed recently") chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) self.layout.addWidget(chartview)
def beforeDelayPieChart(self): series = QPieSeries() labelfont = QFont() labelfont.setPixelSize(11) total_running_time, total_stopped_time = [], [] try: total_running_time = self.tm.total_running_time total_stopped_time = self.tm.total_stopped_time # slices.setPen(QPen(Qt.darkGreen, 2)) # slices.setBrush(QBrush(QColor(0xfdb157))) except AttributeError: self.statusbar.showMessage('Data not ready') series.append("Run", sum(total_running_time)) series.append("Stop", sum(total_stopped_time)) slices = series.slices()[0] slices.setBrush(QBrush(QColor(0x57B1FD))) slices.setLabelVisible() slices.setLabel(("{0} {1:.2f}%").format("Run Time", 100*slices.percentage())) slices.setLabelFont(labelfont) slices1 = series.slices()[1] slices1.setExploded() slices1.setLabelVisible() slices1.setPen(QPen(QColor(0x57B1FD), 2)) slices1.setBrush(QBrush(QColor(0xfdb157))) slices1.setLabel(("{0} {1:.2f}%").format("Stop Time", 100*slices1.percentage())) slices1.setLabelFont(labelfont) chart = QChart() font = QFont() font.setPixelSize(18) chart.setTitleFont(font) chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("Total Time (before)") chart.legend().hide() chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) return chartView
def _create_reviews_due_chart(self): ## TODO: later replace by date selector start, end, chunk = 0, 31, 1 stats = CollectionStats(self.col) ## TODO: refactor stats._due categories_labels = list(range(0, 31, 1)) data = stats.due(start, end, chunk) data = self._transform_first_column_to_key(data) data = self._add_default_value_for_missing_keys( data, [0, 0, 0, 0], categories_labels) series = QStackedBarSeries(self) setYoung = QBarSet("Young", self) [setYoung.append(row[0]) for row in data] setAdolescent = QBarSet("Adolescent", self) [setAdolescent.append(row[1]) for row in data] setMature = QBarSet("Mature", self) [setMature.append(row[2]) for row in data] setOld = QBarSet("Old", self) [setOld.append(row[3]) for row in data] categories = QBarCategoryAxis() categories.setCategories([str(i) for i in categories_labels]) series.append(setOld) series.append(setMature) series.append(setAdolescent) series.append(setYoung) chart = QChart() chart.addSeries(series) chart.createDefaultAxes() chart.setAxisX(categories, series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle("Forecast: the number of reviews due in the future") chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) self.layout.addWidget(chartview)
def main(): import sys from PyQt5.QtChart import QChart, QChartView from PyQt5.QtCore import Qt from PyQt5.QtGui import QPainter from PyQt5.QtWidgets import QApplication, QMainWindow app = QApplication(sys.argv) data = dict() data["Jane"] = [1, 2, 3, 4, 5, 6] # data["John"] = [5, 0, 0, 4, 0, 7] # data["Axel"] = [3, 5, 6, 7, 2, 2] # data["Mary"] = [3, 5, 7, 2, 3, 5] # data["Tony"] = [3, 0, 9, 3 ,1, 2] # series=XDictSet(data, key_order=['Jane', 'John', 'Axel', 'Mary', 'Tony']) series = XDictSet(data) lineseries = XLineSeries(data); print(lineseries) chart = QChart() chart.addSeries(series) chart.addSeries(lineseries[0]) chart.setTitle("Simple horizontal barchart example") chart.setAnimationOptions(QChart.SeriesAnimations) categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] axis = QBarCategoryAxis() axis.append(categories) chart.createDefaultAxes() chart.setAxisX(axis, series) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(800, 600) window.show() sys.exit(app.exec_())