Bonjour,

je voudrais qu'un graphique de mon interface soit mis à jour en fonction des données.
Pour cela je créer le graphique, puis je le place dans une layout et ensuite je l'affiche.
J'ai créé une classe qui s'occupe de cela. Cependant je n'arrive pas a faire la 'mise à jour' du graph.
Pourtant j'essaye une méthode un peu brute, supprimer, puis recrer le graph, mais rien a faire, ca ne marche pas.

Soit le graph s'efface et ne se re-crée pas, soit il ne change pas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class AccountEvoPlot(QtGui.QWidget):
    def __init__(self):
        super(AccountEvoPlot, self).__init__()
 
        # Create plot
        self.makePlot()
 
        posit = QtGui.QHBoxLayout()
        posit.addWidget(FigureCanvas(self.fig))
        self.setLayout(posit)
 
    def makeList(self):
        '''
        Construct data for the graph.
        Return 3 lists (2 are data and 1 is label)
        '''
        # Get list of the last budget (max 12)
        aId = tools.accountId()
        lastBudget = tools.getLastBudgetId()
        budgetList = tools.getBudgetIdList(lastBudget)
        if len(budgetList) > 12:
            budgetList = budgetList[0:12]
        label = []
        listR = []
        listRT = []
        r = 0.0
        c = 0.0
        w = 0.0
        for budgetId in budgetList:
            realSum = calculation.realBudgetSum(budgetId, aId)
            r += realSum
            checkSum = calculation.checkBudgetSum(budgetId, aId)
            c += checkSum
            waitSum = calculation.waitBudgetSum(budgetId, aId)
            w += waitSum
            year = tools.returnVal('Budgets', 'year', budgetId).toString()
            month = tools.returnVal('Budgets', 'mounth', budgetId).toString()
            name = str(month) + '/' + str(year)
            listRT.append(r)
            listR.append(realSum)
            label.append(name)
 
        if len(label) <= 12:
            toAdd = 12 - len(label)
            for i in range(0, toAdd):
                label.append('')
                listR.append(0.0)
                listRT.append(0.0)
 
        return label, listR, listRT
 
    def makePlot(self):
        '''
        Construc the plot
        '''
        # Get data
        label, listR, listRT = self.makeList()
 
        # Give plot's parameters
        N = 12
        ind = np.arange(N)  # the x locations for the groups
        width = 0.35       # the width of the bars
 
        title = tools.returnVal(
            'Accounts', 'info', tools.accountId()).toString()
 
        # Construct the plot
        self.fig, ax = plt.subplots()
 
        # Setup the plot
        ax.set_ylabel(title)
        ax.set_xticks(ind + width)
        ax.set_xticklabels(label)
        ax.bar(ind, listR, width, color='r')
        ax.bar(ind+width, listRT, width, color='y')
 
    def updatePlot(self):
        '''
        UpDate data and plot
        '''
        # Destroy plot
        plt.cla() #or plt.clf, that the same... Don't work
        # Make new plot
        self.makePlot()
        # Print data to be sure that's work
        print 'tools.accountId()', tools.accountId(), 'tools.budgetId()', tools.budgetId()
        label, listR, listRT = self.makeList()
        print label
        print listR
Pour l'utiliser, j'appel plot = AccountEvoPlot()
Pour le mettre à jour plot.updatePlot()

Mais ca ne marche pas. Des idées et/ou conseils?