예제 #1
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.set0 = QtCharts.QBarSet("Jane")
        self.set1 = QtCharts.QBarSet("John")
        self.set2 = QtCharts.QBarSet("Axel")
        self.set3 = QtCharts.QBarSet("Mary")
        self.set4 = QtCharts.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 = QtCharts.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 = QtCharts.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 = QtCharts.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 = QtCharts.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 = QtCharts.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 = QtCharts.QChartView(self.chart)
        self.chartView.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(self.chartView)
    def __init__(self):
        QMainWindow.__init__(self)

        set0 = QtCharts.QBarSet("Jane")
        set1 = QtCharts.QBarSet("John")
        set2 = QtCharts.QBarSet("Axel")
        set3 = QtCharts.QBarSet("Mary")
        set4 = QtCharts.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 = QtCharts.QPercentBarSeries()
        series.append(set0)
        series.append(set1)
        series.append(set2)
        series.append(set3)
        series.append(set4)

        chart = QtCharts.QChart()
        chart.addSeries(series)
        chart.setTitle("Simple percentbarchart example")
        chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)

        categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
        axis = QtCharts.QBarCategoryAxis()
        axis.append(categories)
        chart.createDefaultAxes()
        chart.setAxisX(axis, series)

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

        chart_view = QtCharts.QChartView(chart)
        chart_view.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(chart_view)
예제 #3
0
    def __init__(self):
        QMainWindow.__init__(self)
        low = QtCharts.QBarSet("Min")
        high = QtCharts.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 = QtCharts.QStackedBarSeries()
        series.append(low)
        series.append(high)

        chart = QtCharts.QChart()
        chart.addSeries(series)
        chart.setTitle("Temperature records in celcius")
        chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)

        categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
                      "Aug", "Sep", "Oct", "Nov", "Dec"]
        axisX = QtCharts.QBarCategoryAxis()
        axisX.append(categories)
        axisX.setTitleText("Month")
        chart.addAxis(axisX, Qt.AlignBottom)
        axisY = QtCharts.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 = QtCharts.QChartView(chart)
        chart_view.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(chart_view)
예제 #4
0
    def createBarChart(self):
        chart = QtCharts.QChart()
        chart.setTitle("Bar chart")

        series = QtCharts.QStackedBarSeries(chart)
        for i in range(len(self.data_table)):
            barset = QtCharts.QBarSet("Bar set {}".format(i))
            for data in self.data_table[i]:
                barset.append(data[0].y())
            series.append(barset)

        chart.addSeries(series)

        chart.createDefaultAxes()
        chart.axisY().setRange(0, self.value_max * 2)
        # Add space to label to add space between labels and axis
        chart.axisY().setLabelFormat("%.1f  ")

        return chart
예제 #5
0
 def add_barset(self):
     series_count = self.series.count()
     bar_set = QtCharts.QBarSet("set {}".format(series_count))
     delta = series_count * 0.1
     bar_set.append([1 + delta, 2 + delta, 3 + delta, 4 + delta])
     self.series.append(bar_set)