Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

pyside2 qtcharts updating its self as month elapse



  • I am trying to make a chart where every first of each month the chart updates its self if anyone who has a solution or an idea i would be so grateful.

     def create_bar(self):
         # The QBarSet class represents a set of bars in the bar chart.
         # It groups several bars into a bar set
    
         set0 = QtCharts.QBarSet("markup")
         set1 = QtCharts.QBarSet("liabil")
         # set data
         # initial data = current sales and expenses
         if datetime.now().day == datetime.now().month:
              set0 << self.total_sales()
              set1 << self.total_expenses()
         else:
              set0 << self.total_sales()
              set1 << self.total_expenses()
    
         # load data to chart
          series = QtCharts.QBarSeries()
            series.append(set0)
            series.append(set1)
            # initialize chart
            chart = QtCharts.QChart()
            chart.addSeries(series)
            chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)
    
            categories = datetime.now().strftime('%b')
            axis = QtCharts.QCategoryAxis()
            axisY = QtCharts.QValueAxis()
            axis.append(str(categories), 0)
            chart.addAxis(axisY, QtCore.Qt.AlignLeft)
            series.attachAxis(axisY)
            axisY.setRange(0, 10000)
            chart.setAxisX(axis, series)
    
            chart.legend().setVisible(True)
            chart.legend().setAlignment(Qt.AlignBottom)
    
            self.place = QtWidgets.QVBoxLayout(self)
            self.place = QtWidgets.QVBoxLayout(self.ui.widget_2)
            self.place.setContentsMargins(0, 0, 0, 0)
            self.chartview = QtCharts.QChartView(chart)
            self.chartview.setRenderHint(QPainter.Antialiasing)
            self.chartview.setContentsMargins(0, 0, 0, 0)
            self.place.addWidget(self.chartview)
    


  • @erico

    Where is your question?

    @erico said in pyside2 qtcharts updating its self as month elapse:

    if the current month is over the chart updates

    Cant you just replace this statement with "every first of each month"? When it is the first of any month, the last month is most likely over ;-)

    Edit:

    Since you updated your question... I meant this literally. You could check if datetime.now().day == 1.

    What kind of program is this? Should it keep on running all the time or do you want to update, when you start your program?



  • @Pl45m4 it should keep on updating its self



  • @erico
    Update itself when/in response to what? You have to clarify what you are looking to do.


Log in to reply