class TestChart(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.set0 = QBarSet("Jane") self.set1 = QBarSet("John") self.set2 = QBarSet("Axel") self.set3 = QBarSet("Mary") self.set4 = QBarSet("Sam") self.set0.append([1, 2, 3, 4, 5, 6]) self.set1.append([5, 0, 0, 4, 0, 7]) self.set2.append([3, 5, 8, 13, 8, 5]) self.set3.append([5, 6, 7, 3, 4, 5]) self.set4.append([9, 7, 5, 3, 1, 2]) self.barSeries = QBarSeries() self.barSeries.append(self.set0) self.barSeries.append(self.set1) self.barSeries.append(self.set2) self.barSeries.append(self.set3) self.barSeries.append(self.set4) self.lineSeries = QLineSeries() self.lineSeries.setName("trend") self.lineSeries.append(QPoint(0, 4)) self.lineSeries.append(QPoint(1, 15)) self.lineSeries.append(QPoint(2, 20)) self.lineSeries.append(QPoint(3, 4)) self.lineSeries.append(QPoint(4, 12)) self.lineSeries.append(QPoint(5, 17)) self.chart = QChart() self.chart.addSeries(self.barSeries) self.chart.addSeries(self.lineSeries) self.chart.setTitle("Line and barchart example") self.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] self.axisX = QBarCategoryAxis() self.axisX.append(self.categories) self.chart.setAxisX(self.axisX, self.lineSeries) self.chart.setAxisX(self.axisX, self.barSeries) self.axisX.setRange("Jan", "Jun") self.axisY = QValueAxis() self.chart.setAxisY(self.axisY, self.lineSeries) self.chart.setAxisY(self.axisY, self.barSeries) self.axisY.setRange(0, 20) self.chart.legend().setVisible(True) self.chart.legend().setAlignment(Qt.AlignBottom) self.chartView = QChartView(self.chart) self.chartView.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(self.chartView)
def plot_data(self): # Get table information series = QBarSeries() for i in range(self.table.rowCount()): text = self.table.item(i, 0).text() number = float(self.table.item(i, 1).text()) bar_set = QBarSet(text) bar_set.append(number) series.append(bar_set) chart = QChart() chart.addSeries(series) chart.legend().setAlignment(Qt.AlignLeft) self.chart_view.setChart(chart)
def __init__(self): QMainWindow.__init__(self) low = QBarSet("Min") high = QBarSet("Max") low.append([-52, -50, -45.3, -37.0, -25.6, -8.0, -6.0, -11.8, -19.7, -32.8, -43.0, -48.0]) high.append([11.9, 12.8, 18.5, 26.5, 32.0, 34.8, 38.2, 34.8, 29.8, 20.4, 15.1, 11.8]) series = QStackedBarSeries() series.append(low) series.append(high) chart = QChart() chart.addSeries(series) chart.setTitle("Temperature records in celcius") chart.setAnimationOptions(QChart.SeriesAnimations) categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] axisX = QBarCategoryAxis() axisX.append(categories) axisX.setTitleText("Month") chart.addAxis(axisX, Qt.AlignBottom) axisY = QValueAxis() axisY.setRange(-52, 52) axisY.setTitleText("Temperature [°C]") chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisX) series.attachAxis(axisY) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chart_view = QChartView(chart) chart_view.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(chart_view)
def add_barset(self): series_count = self.series.count() bar_set = QBarSet(f"set {series_count}") delta = series_count * 0.1 bar_set.append([1 + delta, 2 + delta, 3 + delta, 4 + delta]) self.series.append(bar_set)
def __init__(self): QMainWindow.__init__(self) set0 = QBarSet("Jane") set1 = QBarSet("John") set2 = QBarSet("Axel") set3 = QBarSet("Mary") set4 = QBarSet("Samantha") 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 = QPercentBarSeries() series.append(set0) series.append(set1) series.append(set2) series.append(set3) series.append(set4) chart = QChart() chart.addSeries(series) chart.setTitle("Simple percentbarchart 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) chart_view = QChartView(chart) chart_view.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(chart_view)