'Run "Series not in the chart. Please addSeries to chart first" error?

I had write a simple demo, but it throw Series not in the chart. Please addSeries to chart first. warnning, But the demo work fine, what happend here?

from PyQt5.QtSql import *
from PyQt5.QtWidgets import *
from PyQt5.QtChart import *
from PyQt5.QtCore import *

import pandas as pd

class BarChart(QChartView):
    def __init__(self):
        super().__init__()
        d = pd.Series({"A":12, "B": 13, "C": 24})

        ser = QBarSeries()
        ser.setLabelsVisible(True)
        for k, v in d.to_dict().items():
            barset = QBarSet(k)
            barset.append(v)
            ser.append(barset)

        cat = QBarCategoryAxis()
        cat.append(d.to_dict().keys())
        ser.attachAxis(cat)

        self.chart().addAxis(cat, Qt.AlignBottom)
        self.chart().addSeries(ser)

app  = QApplication([])
view = BarChart()
view.show()
app.exec()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source