Data not appearing on graphs after turning them into images

This has been a real headscratcher for a while. I’ve been working to intergrate a print function for my desktop app program where the users can print a document with the generated graphs added on it. Before I do that, I need to find a way to save the graphs as images. After many attempts, I only managed to print out images of the graphs before the data was to be added, even though I saved these images right after adding the values from a CSV file into the graph. Here’s what the image for the temperature bar chart looks like after being saved as an image:


And this is what the bar chat is supposed to look like:

I’m not sure if the problem here is how I’m adding the values to the graph. Here’s what I wrote to design the temperature graph, as well as how it is being saved:

def create_temp_chart(self):
        if not self.fileName:
            return
        low = QtChart.QBarSet("min")
        high = QtChart.QBarSet("max")
        ltemp = []
        htemp = []

        with open(self.fileName) as csvfile:
            csvreader = csv.reader(csvfile, delimiter=',')
            header_found = False
            for row in csvreader:
                if row[0] == "MinTemp":
                    header_found = True
                    continue
                if header_found:
                    ltemp.append(float(row[0]))
                    htemp.append(float(row[1]))
                if len(ltemp) >= 12:
                    break  # Assuming only the first 12 months of data are needed

        low.append(ltemp)
        high.append(htemp)

        series = QtChart.QStackedBarSeries()
        series.append(low)
        series.append(high)

        chart = QtChart.QChart()
        chart.addSeries(series)
        chart.setTitle("Muestra de Temperatura en Celsius")
        chart.setAnimationOptions(QtChart.QChart.AnimationOption.SeriesAnimations)

        category = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

        axisX = QtChart.QBarCategoryAxis()
        axisX.append(category)
        axisX.setTitleText("Mes")
        chart.addAxis(axisX, Qt.AlignmentFlag.AlignBottom)
        axisY = QtChart.QValueAxis()
        axisY.setRange(-52, 52)
        axisY.setTitleText("Temperatura en Celsius")
        chart.addAxis(axisY, Qt.AlignmentFlag.AlignLeft)
        series.attachAxis(axisX)
        series.attachAxis(axisY)

        self.ui.chart_view_temp = QtChart.QChartView(chart)
        self.ui.chart_view_temp.setRenderHint(QPainter.RenderHint.Antialiasing)
        self.ui.chart_view_temp.chart().setTheme(QtChart.QChart.ChartTheme.ChartThemeDark)
        sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
        sizePolicy.setHeightForWidth(self.ui.chart_view_temp.sizePolicy().hasHeightForWidth())
        self.ui.chart_view_temp.setSizePolicy(sizePolicy)

        self.ui.gridLayout_2.addWidget(self.ui.chart_view_temp)
        self.ui.frame_18.setStyleSheet(u"background-color: transparent")

        # Save chart as image
        self.save_chart_as_image(self.ui.chart_view_temp, "temp_chart.png")

def save_chart_as_image(self, chart_view, file_name):
        QApplication.processEvents()  # Process all pending events to ensure rendering is complete

        image = QImage(chart_view.size(), QImage.Format.Format_ARGB32)
        painter = QPainter(image)
        chart_view.render(painter)
        painter.end()
        image.save(file_name)

        # Display the image after saving
        self.display_image(file_name)

def display_image(self, file_path):
        dialog = QDialog(self)
        dialog.setWindowTitle("Chart Image")
        layout = QVBoxLayout()
        label = QLabel()
        pixmap = QPixmap(file_path)
        label.setPixmap(pixmap)
        layout.addWidget(label)
        dialog.setLayout(layout)
        dialog.exec_()

Am I doing something wrong? What should I do to fix this?

What do ltemp and htemp look like? Do they actually contain values after reading the CSV file?