Bonjour,

Après avoir réalisé un graphique à partir de points extraits d'un datagrid, je réalise une première courbe de tendance (loi de puissance) sur l'ensemble des points puis une seconde en omettant le premier point.
Jusque là mon code fonctionne...

Maintenant je souhaite que ma courbe de tendance ne commence non pas au 1er point sélectionné mais à l'origine de mon graphique (0,0)...et là je ne trouve rien sur la façon de faire.

J'ai bien pensé ajouté le point 0,0 mais je ne peux forcer le passage par ce point et de toute façon ça fait bugger le calcul des coefficients a et b de l'équation de ma courbe de tendance...

Donc si quelqu'un à un début de solution... merci

Karen



Pour info, voici le code qui me sert à tracer mes courbes :

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
For Each Ligne As DataGridViewRow In DataGridView2.Rows
            If Not IsNothing(Ligne.Cells.Item(1).Value) Then
                ChartEta.Series.Item(0).Points.AddXY(Ligne.Cells.Item(0).Value, Ligne.Cells.Item(2).Value)
            End If
        Next
 
        ChartEta.Series.Item(1).Points.AddXY(DataGridView2.Rows(0).Cells.Item(0).Value, Double.NaN)
        For i = 1 To DataGridView2.Rows.Count - 1
            Dim Ligne As DataGridViewRow = DataGridView2.Rows.Item(i)
            If Not IsNothing(Ligne.Cells.Item(1).Value) Then
                ChartEta.Series.Item(1).Points.AddXY(Ligne.Cells.Item(0).Value, Ligne.Cells.Item(2).Value)
            End If
        Next
 
        ChartEta.Series.Item(2).Points.AddXY(DataGridView2.Rows(0).Cells.Item(0).Value, Double.NaN)
        ChartEta.Series.Item(2).Points.AddXY(DataGridView2.Rows(1).Cells.Item(0).Value, Double.NaN)
 
        For i = 2 To DataGridView2.Rows.Count - 1
            Dim Ligne As DataGridViewRow = DataGridView2.Rows.Item(i)
            If Not IsNothing(Ligne.Cells.Item(1).Value) Then
                ChartEta.Series.Item(2).Points.AddXY(Ligne.Cells.Item(0).Value, Ligne.Cells.Item(2).Value)
            End If
        Next
 
 'tracer la courbe de tendance la mieux ajustée
        ChartEta.Series.Add("Trendline")
        ChartEta.Series("Trendline").ChartType = SeriesChartType.Line
        ChartEta.Series("Trendline").Color = Color.Red
        ChartEta.DataManipulator.IsStartFromFirst = True
        ChartEta.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, "Power,1,false,false", ChartEta.Series.Item(0), ChartEta.Series("Trendline"))
 
        'définir les coefficients a et b
        Dim PointsSaisis As DataPointCollection = ChartEta.Series.Item(0).Points
        Dim xx(PointsSaisis.Count - 1) As Double
        Dim yy(PointsSaisis.Count - 1) As Double
        For i = 0 To PointsSaisis.Count - 1
            xx(i) = Double.Parse(PointsSaisis(i).AxisLabel.Replace(",", "."))
            yy(i) = PointsSaisis(i).YValues(0)
        Next
 
        Dim r = Fit.Power(xx, yy)
        DataGridView1.Item(1, 0).Value = r.A
        DataGridView1.Item(2, 0).Value = r.B
 
 
        ChartEta.Series.Add("Trendline1")
        ChartEta.Series("Trendline1").ChartType = SeriesChartType.Line
        ChartEta.Series("Trendline1").Color = Color.Blue
        ChartEta.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, "Power,1,false,false", ChartEta.Series.Item(1), ChartEta.Series("Trendline1"))
 
        'définir les coefficients a et b
        PointsSaisis = ChartEta.Series.Item(1).Points
        ReDim xx(PointsSaisis.Count - 2)
        ReDim yy(PointsSaisis.Count - 2)
        For i = 0 To PointsSaisis.Count - 2
            xx(i) = Double.Parse(PointsSaisis(i + 1).AxisLabel.Replace(",", "."))
            yy(i) = PointsSaisis(i + 1).YValues(0)
        Next
 
        r = Fit.Power(xx, yy)
        DataGridView1.Item(1, 1).Value = r.A
        DataGridView1.Item(2, 1).Value = r.B