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)
示例#2
0
class TestChart(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.series = QLineSeries()
        self.series.append([
            QPointF(1.0, 1.0),
            QPointF(2.0, 73.0),
            QPointF(3.0, 268.0),
            QPointF(4.0, 17.0),
            QPointF(5.0, 4325.0),
            QPointF(6.0, 723.0)
        ])

        self.chart = QChart()
        self.chart.addSeries(self.series)
        self.chart.legend().hide()
        self.chart.setTitle("Logarithmic axis example")

        self.axisX = QValueAxis()
        self.axisX.setTitleText("Data point")
        self.axisX.setLabelFormat("%i")
        self.axisX.setTickCount(self.series.count())
        self.chart.addAxis(self.axisX, Qt.AlignBottom)
        self.series.attachAxis(self.axisX)

        self.axisY = QLogValueAxis()
        self.axisY.setTitleText("Values")
        self.axisY.setLabelFormat("%g")
        self.axisY.setBase(8.0)
        self.axisY.setMinorTickCount(-1)
        self.chart.addAxis(self.axisY, Qt.AlignLeft)
        self.series.attachAxis(self.axisY)

        self.chartView = QChartView(self.chart)
        self.chartView.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(self.chartView)