IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Aide création d un graphique avec point mobile drag and drop


Sujet :

VB.NET

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut Aide création d un graphique avec point mobile drag and drop
    Bonjour voila je voudrais savoir s'il est possible de charger un tableau avec 4 courbes de 10 points chacune
    avec la possibilité de :
    bouger les points avec la souris mais également la possibilité de rentrée les coordonné du point.
    Une fois les points paramètres j aimerais récupèrent les valeurs dans un fichier
    Merci pour vos réponses :p

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    une video vaut plus que des mots j aimerais faire le même style de graphique

  3. #3
    Membre expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Points : 3 570
    Points
    3 570
    Par défaut
    Salut,

    tu utilises un contrôle ChartChépakoi ou tu pars from scratch ?
    Plus je connais de langages, plus j'aime le C.

  4. #4
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Le control Chart de Microsoft permet cela et bien plus ,mais il faut que tu le code...

    Mais tu dois donner ton code pour qu'on puisse t'aider ....
    Avec des videos on est plutôt parti pour visionner le dernier jeu de StartRek !!!

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Citation Envoyé par MABROUKI Voir le message
    bonjour

    Le control Chart de Microsoft permet cela et bien plus ,mais il faut que tu le code...

    Mais tu dois donner ton code pour qu'on puisse t'aider ....
    Avec des videos on est plutôt parti pour visionner le dernier jeu de StartRek !!!
    Bonjour Mabrouki,

    Voici mon code pour générer les 4 courbes en question dans mon chart. Un bouton est mis à jours toutes les seconde via un timer (points de courbes récupérés via des textbox car l'utilisateur interagi avec les données)

    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    'MAJ COURBE
            Try
     
                Me.Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.Transparent
                'Rendre la couleur du quadrillage dans le sens y transparente
                Me.Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.Transparent
     
                '-------------------------------------------------------------------------------------------
                'Canal A
                Me.Chart1.Series.Clear()
                Me.Chart1.Series.Add("Canal A")
                Me.Chart1.Series(0).ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                Me.Chart1.Series(0).BackGradientStyle = GradientStyle.Center
                Me.Chart1.Series(0).BorderWidth = 3
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH1_CA.Text), Val(txt_valeur1CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH2_CA.Text), Val(txt_valeur2CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH3_CA.Text), Val(txt_valeur3CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH4_CA.Text), Val(txt_valeur4CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH5_CA.Text), Val(txt_valeur5CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH6_CA.Text), Val(txt_valeur6CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH7_CA.Text), Val(txt_valeur7CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH8_CA.Text), Val(txt_valeur8CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH9_CA.Text), Val(txt_valeur9CA.Text))
                Me.Chart1.Series("Canal A").Points.AddXY(Val(ParaH10_CA.Text), Val(txt_valeur10CA.Text))
                Me.Chart1.Series(0).MarkerSize = 10
                Me.Chart1.Series(0).MarkerStyle = MarkerStyle.Circle
                Chart1.ChartAreas(0).AlignmentOrientation = AreaAlignmentOrientations.Horizontal
     
     
                '-------------------------------------------------------------------------------------------
                'Canal B
                Me.Chart1.Series.Add("Canal B")
                Me.Chart1.Series(1).ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                Me.Chart1.Series(1).BackGradientStyle = GradientStyle.Center
                Me.Chart1.Series(1).BorderWidth = 3
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH1_CB.Text), Val(txt_valeur1CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH2_CB.Text), Val(txt_valeur2CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH3_CB.Text), Val(txt_valeur3CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH4_CB.Text), Val(txt_valeur4CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH5_CB.Text), Val(txt_valeur5CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH6_CB.Text), Val(txt_valeur6CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH7_CB.Text), Val(txt_valeur7CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH8_CB.Text), Val(txt_valeur8CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH9_CB.Text), Val(txt_valeur9CB.Text))
                Me.Chart1.Series("Canal B").Points.AddXY(Val(ParaH10_CB.Text), Val(txt_valeur10CB.Text))
                Me.Chart1.Series(1).MarkerSize = 10
                Me.Chart1.Series(1).MarkerStyle = MarkerStyle.Circle
                '------------------------------------------------------------------------------------------
     
                '-------------------------------------------------------------------------------------------
                'Canal C
                Me.Chart1.Series.Add("Canal C")
                Me.Chart1.Series(2).ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                Me.Chart1.Series(2).BackGradientStyle = GradientStyle.Center
                Me.Chart1.Series(2).BorderWidth = 3
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH1_CC.Text), Val(txt_valeur1CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH2_CC.Text), Val(txt_valeur2CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH3_CC.Text), Val(txt_valeur3CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH4_CC.Text), Val(txt_valeur4CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH5_CC.Text), Val(txt_valeur5CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH6_CC.Text), Val(txt_valeur6CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH7_CC.Text), Val(txt_valeur7CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH8_CC.Text), Val(txt_valeur8CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH9_CC.Text), Val(txt_valeur9CC.Text))
                Me.Chart1.Series("Canal C").Points.AddXY(Val(ParaH10_CC.Text), Val(txt_valeur10CC.Text))
                Me.Chart1.Series(2).MarkerSize = 10
                Me.Chart1.Series(2).MarkerStyle = MarkerStyle.Circle
                '------------------------------------------------------------------------------------------
     
                '-------------------------------------------------------------------------------------------
                'Canal D
                Me.Chart1.Series.Add("Canal D")
                Me.Chart1.Series(3).ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                Me.Chart1.Series(3).BackGradientStyle = GradientStyle.Center
                Me.Chart1.Series(3).BorderWidth = 3
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH1_CD.Text), Val(txt_valeur1CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH2_CD.Text), Val(txt_valeur2CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH3_CD.Text), Val(txt_valeur3CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH4_CD.Text), Val(txt_valeur4CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH5_CD.Text), Val(txt_valeur5CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH6_CD.Text), Val(txt_valeur6CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH7_CD.Text), Val(txt_valeur7CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH8_CD.Text), Val(txt_valeur8CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH9_CD.Text), Val(txt_valeur9CD.Text))
                Me.Chart1.Series("Canal D").Points.AddXY(Val(ParaH10_CD.Text), Val(txt_valeur10CD.Text))
                Me.Chart1.Series(3).MarkerSize = 10
                Me.Chart1.Series(3).MarkerStyle = MarkerStyle.Circle
                '------------------------------------------------------------------------------------------
     
                'Canal valeur mini et maxi
                Me.Chart1.Series.Add(" ")
                Me.Chart1.Series(4).ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                Me.Chart1.Series(4).BackGradientStyle = GradientStyle.Center
                Me.Chart1.Series(4).BorderWidth = 3
                Me.Chart1.Series(" ").Points.AddXY(0, 0)
                Me.Chart1.Series(" ").Points.AddXY(24, 0)
     
     
            Catch ex As Exception
     
            End Try

    L'idée c'est de pouvoir déplacer chaque point avec la souris sur l'axe des X et Y en récupérant ces nouvelles valeurs dans le textbox concerné
    Si vous avez des idées je suis preneur

    Merci à tous pour vos éventuel piste

  6. #6
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    La fonction Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X) permet de convertir la valeur e.X (valeur en pixel ) en valeur absolue dans la Zone graphique(le chartarea)...
    Moyennant cette fonction de conversion et à condition que la position souris convertie ne sorte pas des limites d'axes principal X données par :
    - Chart1.ChartAreas(0).AxisX.Minimum
    - Chart1.ChartAreas(0).AxisX.Maximum
    et idem pour les limites d'axes principal Y ....
    On peut sélectionner un point du graphe et le "draguer" avec souris...
    code .vb exmple :
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
     
    Imports System.Windows.Forms.DataVisualization.Charting
     
    Public Class FormDataPoints
        Private points As New List(Of PointF)
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Chart1.Series(0).Points.Clear()
            GetData()
        End Sub
        Private Sub GetData()
            Dim rnd As New Random
            For x As Double = 0 To 100
     
                Dim y As Double = 14 * x
                points.Add(New PointF(x, y))
            Next
     
            'DataGridView1.DataSource = points
     
     
            Chart1.Series(0).ChartType = SeriesChartType.Line
            Chart1.Series(0).XValueMember = "X"
            Chart1.Series(0).YValueMembers = "Y"
            Chart1.Series(0).BorderWidth = 2
     
     
            Chart1.Series(0).MarkerColor = Color.Brown
            Chart1.Series(0).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(0).MarkerSize = 8
            With Chart1.Series(0)
                .Name = "Series Points"
                .Points.DataBind(points, "X", "Y", Nothing)
            End With
     
     
            'Move legend to bottom and center
            Chart1.Legends(0).Docking = Docking.Bottom
            Chart1.Legends(0).Alignment = StringAlignment.Center
     
        End Sub
     
     
     
        Private selectedDataPoint As DataPoint = Nothing
        Private Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown
            selectedDataPoint = Nothing
     
            If e.Button = MouseButtons.Left Then
                Dim hitResult As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResult Is Nothing Then Return
                If hitResult.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPoint = CType(hitResult.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPoint.IsValueShownAsLabel = True
                End If
     
     
     
            End If
        End Sub
     
        Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                '  X value from current cursor position
                Dim xValue As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                xValue = Math.Max(xValue, Chart1.ChartAreas(0).AxisX.Minimum)
                xValue = Math.Min(xValue, Chart1.ChartAreas(0).AxisX.Maximum)
     
            '  Y value from current cursor position
                Dim yValue As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                yValue = Math.Max(yValue, Chart1.ChartAreas(0).AxisY.Minimum)
                yValue = Math.Min(yValue, Chart1.ChartAreas(0).AxisY.Maximum)
     
     
            ' Update selected point X,Y value
     
            selectedDataPoint.XValue = xValue
                'selectedDataPoint.XValue = -selectedDataPoint.XValue
            selectedDataPoint.YValues(0) = yValue
     
            ' Invalidate chart
            Chart1.Invalidate()
            End If
     
     
        End Sub
     
        Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseUp
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPoint.IsValueShownAsLabel = False
     
                ' reset selected object
                selectedDataPoint = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
     
            End If
        End Sub
    End Class
    bon code....

  7. #7
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Bonjour,

    Merci infiniment Mabrouki pour ce super exemple concret (qui fonctionne à merveille)

    Dans mon projet l'axe des X correspond aux heures de 0 à 24h et l'axe des Y une valeur 0 a 4095. Chaque courbe possède 10 points.
    J'essai en vain depuis ce matin de reprendre ton exemple et de récupérer chaque coordonnée X et Y de chaque point dans des texbox mais sans succès
    Est-ce que cela est possible de dissocier chacun des 10 points afin de pouvoir récupérer sa valeur X (textboxP1X) et Y (textboxP1Y) ?

    je récupère la valeur X et Y "en cours" via ton code mais j'ai du mal à dissocier mes 10 points :

    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
     
    Imports System.Windows.Forms.DataVisualization.Charting
     
    Public Class Form1
        Private points As New List(Of PointF)
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Chart1.Series(0).Points.Clear()
            GetData()
     
        End Sub
        Private Sub GetData()
     
            Dim rnd As New Random
     
            For x1 As Double = 8 To 17
     
                Dim y1 As Double = 100 * x1
                points.Add(New PointF(x1, y1))
            Next
     
            'DataGridView1.DataSource = points
     
            Chart1.Series(0).ChartType = SeriesChartType.Line
            Chart1.Series(0).XValueMember = "X"
            Chart1.Series(0).YValueMembers = "Y"
            Chart1.Series(0).BorderWidth = 2
     
     
            Chart1.Series(0).MarkerColor = Color.DodgerBlue
            Chart1.Series(0).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(0).MarkerSize = 15
            With Chart1.Series(0)
                .Name = "Canal A"
                .Points.DataBind(points, "X", "Y", Nothing)
     
            End With
     
     
            'Move legend to bottom and center
            Chart1.Legends(0).Docking = Docking.Bottom
            Chart1.Legends(0).Alignment = StringAlignment.Center
     
        End Sub
     
        Private selectedDataPoint As DataPoint = Nothing
        Private Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown
            selectedDataPoint = Nothing
     
            If e.Button = MouseButtons.Left Then
                Dim hitResult As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResult Is Nothing Then Return
                If hitResult.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPoint = CType(hitResult.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPoint.IsValueShownAsLabel = True
                End If
     
     
            End If
        End Sub
     
        Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
     
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                Try
                    '  X value from current cursor position
                    Dim x1Value As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                    x1Value = Math.Round(Math.Max(x1Value, Chart1.ChartAreas(0).AxisX.Minimum), 0)
                    x1Value = Math.Round(Math.Min(x1Value, Chart1.ChartAreas(0).AxisX.Maximum), 0)
     
                    ' Update selected point X,Y value
                    selectedDataPoint.XValue = x1Value
     
                    ' recup value X
                    textboxP1X.Text = x1Value
     
                Catch ex As Exception
     
                End Try
     
                Try
                    '  Y value from current cursor position
                    Dim y1Value As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                    y1Value = Math.Round(Math.Max(y1Value, Chart1.ChartAreas(0).AxisY.Minimum), 0)
                    y1Value = Math.Round(Math.Min(y1Value, Chart1.ChartAreas(0).AxisY.Maximum), 0)
     
                    'selectedDataPoint.XValue = -selectedDataPoint.XValue
                    selectedDataPoint.YValues(0) = y1Value
     
                     ' recup value X
                    textboxP1Y.Text = y1Value
     
                Catch ex As Exception
     
                End Try
     
                ' Invalidate chart
                Chart1.Invalidate()
            End If
     
     
        End Sub
     
        Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseUp
     
            If selectedDataPoint Is Nothing Then Return
     
            If e.Button = MouseButtons.Right Then
     
                ' Hide point label
                selectedDataPoint.IsValueShownAsLabel = False
     
                ' reset selected object
                selectedDataPoint = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
            End If
        End Sub
    End Class

  8. #8
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    re

    je récupère la valeur X et Y "en cours" via ton code mais j'ai du mal à dissocier mes 10 points :
    Qu'Est-ce à dire? Pas clair comme question...Si tu veux connaitre la position du point "draggué" dans la liste hitResult le fournit....
    Mais c'est un type DataPoint qu'il faut reconvertir en PointF ce qui permet la MAJ de la liste "points" sous-jacente....

    Un BindinSource permet le suivi de la liste 'points" et fait cette MAJ....
    Plus 2 TextBoxes bindés au BindingSource (valeurs Pointf.X et Pointf.Y)....

    code revu .vb revu légèrement :
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
     
    Imports System.Windows.Forms.DataVisualization.Charting
     
    Public Class Form4
        Private points As New List(Of PointF)
        Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Chart1.Series(0).Points.Clear()
            GetData()
        End Sub
        Private Sub GetData()
            Dim rnd As New Random
            For x As Double = 0 To 25
     
                Dim y As Double = 14 * x
                points.Add(New PointF(x, y))
            Next
            BindingSource1.DataSource = points
     
     
     
            Chart1.Series(0).ChartType = SeriesChartType.Line
            Chart1.Series(0).XValueMember = "X"
            Chart1.Series(0).YValueMembers = "Y"
            Chart1.Series(0).BorderWidth = 2
     
     
            Chart1.Series(0).MarkerColor = Color.Brown
            Chart1.Series(0).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(0).MarkerSize = 4
            With Chart1.Series(0)
                .Name = "Series Points"
            End With
     
     
     
     
            'Move legend to bottom and center
            Chart1.Legends(0).Docking = Docking.Bottom
            Chart1.Legends(0).Alignment = StringAlignment.Center
     
            '-----------------les Bindings-----------------
     
            Chart1.Series(0).Points.DataBind(BindingSource1, "X", "Y", Nothing)
            Chart1.DataBind()
            ListBox1.DataSource = BindingSource1
     
     
            txtX.DataBindings.Add("Text", BindingSource1, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtY.DataBindings.Add("Text", BindingSource1, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
     
        End Sub
        '-----------------RAJOUT-----------------
        Private selectedPointF As PointF = Nothing
        Private position As Integer = 0
        '---------------------------------
        Private selectedDataPoint As New DataPoint
        Private Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown
            selectedDataPoint = Nothing
            position = -1
            If e.Button = MouseButtons.Left Then
                Dim hitResult As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResult Is Nothing Then Return
                If hitResult.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPoint = CType(hitResult.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPoint.IsValueShownAsLabel = True
                    '-----------------MAJ POINTS-----------------
                    position = hitResult.PointIndex
                    selectedPointF = New PointF(selectedDataPoint.XValue, selectedDataPoint.YValues(0))
                End If
            End If
     
        End Sub
     
        Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                '  X value from current cursor position
                Dim xValue As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                xValue = Math.Max(xValue, Chart1.ChartAreas(0).AxisX.Minimum)
                xValue = Math.Min(xValue, Chart1.ChartAreas(0).AxisX.Maximum)
     
                '  Y value from current cursor position
                Dim yValue As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                yValue = Math.Max(yValue, Chart1.ChartAreas(0).AxisY.Minimum)
                yValue = Math.Min(yValue, Chart1.ChartAreas(0).AxisY.Maximum)
     
     
                ' Update selected point X,Y value
     
                selectedDataPoint.XValue = xValue
                'selectedDataPoint.XValue = -selectedDataPoint.XValue
                selectedDataPoint.YValues(0) = yValue
     
                selectedPointF = New PointF(selectedDataPoint.XValue, selectedDataPoint.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                points(position) = selectedPointF
                ResumeLiaison()
     
     
                ' Invalidate chart
                Chart1.Invalidate()
            End If
     
     
        End Sub
     
        Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseUp
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPoint.IsValueShownAsLabel = False
                selectedPointF = New PointF(selectedDataPoint.XValue, selectedDataPoint.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                points(position) = selectedPointF
     
                ResumeLiaison()
     
                ' reset selected object
                selectedDataPoint = Nothing
     
     
     
                ' Invalidate chart
                Chart1.Invalidate()
     
     
     
            End If
        End Sub
        Private Sub ResumeLiaison()
     
     
            BindingSource1.ResetBindings(True)
            BindingSource1.Position = position
        End Sub
     
     
     
     
    End Class
    Bon code..

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Wahouuu ! Top !

    Les 10 coordonnées X et Y des 10 points sont bien récupérés dans la listbox je vois peut être enfin une solution pour récupérer ces valeurs indépendamment dans chacun de mes textbox


    A la fin de l'évement Mouse_Move, est-il possible de traiter et filtrer chaque ligne du listbox afin de dispatcher les valeurs X et Y dans mes fameux textbox en question ?

    Par exemple :

    coordonnée du point n°1 (ligne n°1 de la listbox) : {X=8, Y=2000} alors Txt_X1.text = 8 et Txt_Y1.text = 2000
    coordonnée du point n°2 (ligne n°2 de la listbox) : {X=10, Y=2550} alors Txt_X2.text = 10 et Txt_Y2.text = 2550
    ect..
    jusqu'à mon point n°10

    Placer cela dans mon évenement Mouse_Move me permettrai d'avoir les dernières valeurs actualisées choisie par l'utilisateur afin de pouvoir les traiter en aval et/ou les modifier

    Je vois que tu récupère les valeurs X et Y dans le txtX et TxtY mais j'aimerai y ajouter la ligne concernée afin de pouvoir les dissocier :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    txtX1.DataBindings.Add('Listbox ligne1 "Text", BindingSource1, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtY1.DataBindings.Add('Listbox ligne1 "Text", BindingSource1, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
    
    txtX2.DataBindings.Add('Listbox ligne2 "Text", BindingSource1, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtY2.DataBindings.Add('Listbox ligne2 "Text", BindingSource1, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
    
    ect...

    Merci pour ton aide précieuse Mabrouki

  10. #10
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    re

    Bah ,tu n'as qu'a rajouter un TextBox pour suivre l'index dans la liste " points" sous-jacent dans l'event :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     Private Sub BindingSource1_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingSource1.PositionChanged
            txtIndex.Text = BindingSource1.Position.ToString
     
        End Sub
    bon code...

  11. #11
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Yes c'est super ! merci pour ton retour + que rapide

    Comment pourrais-je m'y prendre pour conserver les positions de mes 10 points "dragués" après la ré-ouverture de ma form ?

    PS: J'ai déja supprimé "Me.Chart1.Series(0).Points.Clear()" sur l'event Form_Load

  12. #12
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Bonjour,

    Dans la continuité de mon post j'ai donc créer ma série avec mes fameux textbox, je récupère les valeurs en suivant l'index comme le conseille Mabrouki

    J'essai sans succès de reprendre l'exemple de Mabrouki afin d’insérer une 2ème série au Chart1 (j'aimerai créer 4 séries au total dans le Chart1), voici ce que j'ai essayé selon son exemple :

    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
     
    Imports System.Windows.Forms.DataVisualization.Charting
     
    Public Class Form1
     
        Private pointsA As New List(Of PointF)
        Private pointsB As New List(Of PointF)
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
            GetData()
            Timer_recup_graph.Start()
        End Sub
     
        Private Sub GetData()
     
            Dim rnd As New Random
     
            'Canal A
            pointsA.Add(New PointF(ParaH1_CA.Text, txt_valeur1CA.Text))
            pointsA.Add(New PointF(ParaH2_CA.Text, txt_valeur2CA.Text))
            pointsA.Add(New PointF(ParaH3_CA.Text, txt_valeur3CA.Text))
            pointsA.Add(New PointF(ParaH4_CA.Text, txt_valeur4CA.Text))
            pointsA.Add(New PointF(ParaH5_CA.Text, txt_valeur5CA.Text))
            pointsA.Add(New PointF(ParaH6_CA.Text, txt_valeur6CA.Text))
            pointsA.Add(New PointF(ParaH7_CA.Text, txt_valeur7CA.Text))
            pointsA.Add(New PointF(ParaH8_CA.Text, txt_valeur8CA.Text))
            pointsA.Add(New PointF(ParaH9_CA.Text, txt_valeur9CA.Text))
            pointsA.Add(New PointF(ParaH10_CA.Text, txt_valeur10CA.Text))
     
            BindingSourceA.DataSource = pointsA
     
            Chart1.Series(0).ChartType = SeriesChartType.Line
            Chart1.Series(0).XValueMember = "X"
            Chart1.Series(0).YValueMembers = "Y"
            Chart1.Series(0).BorderWidth = 2
     
            Chart1.Series(0).MarkerColor = Color.Blue
            Chart1.Series(0).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(0).MarkerSize = 18
            With Chart1.Series(0)
                .Name = "Canal A"
            End With
     
            'Move legend to bottom and center
            Chart1.Legends(0).Docking = Docking.Bottom
            Chart1.Legends(0).Alignment = StringAlignment.Center
     
            ' les Bindings
     
            Chart1.Series(0).Points.DataBind(BindingSourceA, "X", "Y", Nothing)
            Chart1.DataBind()
            ListBoxA.DataSource = BindingSourceA
     
            txtXA.DataBindings.Add("Text", BindingSourceA, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtYA.DataBindings.Add("Text", BindingSourceA, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
            '---------------------------------------------------------------------------------------------------
     
            'Canal B
            pointsB.Add(New PointF(ParaH1_CB.Text, txt_valeur1CB.Text))
            pointsB.Add(New PointF(ParaH2_CB.Text, txt_valeur2CB.Text))
            pointsB.Add(New PointF(ParaH3_CB.Text, txt_valeur3CB.Text))
            pointsB.Add(New PointF(ParaH4_CB.Text, txt_valeur4CB.Text))
            pointsB.Add(New PointF(ParaH5_CB.Text, txt_valeur5CB.Text))
            pointsB.Add(New PointF(ParaH6_CB.Text, txt_valeur6CB.Text))
            pointsB.Add(New PointF(ParaH7_CB.Text, txt_valeur7CB.Text))
            pointsB.Add(New PointF(ParaH8_CB.Text, txt_valeur8CB.Text))
            pointsB.Add(New PointF(ParaH9_CB.Text, txt_valeur9CB.Text))
            pointsB.Add(New PointF(ParaH10_CB.Text, txt_valeur10CB.Text))
     
            BindingSourceB.DataSource = pointsB
     
            Chart1.Series(1).ChartType = SeriesChartType.Line
            Chart1.Series(1).XValueMember = "X"
            Chart1.Series(1).YValueMembers = "Y"
            Chart1.Series(1).BorderWidth = 2
     
            Chart1.Series(1).MarkerColor = Color.Blue
            Chart1.Series(1).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(1).MarkerSize = 18
            With Chart1.Series(1)
                .Name = "Canal B"
            End With
     
            ' les Bindings
            Chart1.Series(1).Points.DataBind(BindingSourceB, "X", "Y", Nothing)
            Chart1.DataBind()
            ListBoxB.DataSource = BindingSourceB
     
            txtXB.DataBindings.Add("Text", BindingSourceB, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtYB.DataBindings.Add("Text", BindingSourceB, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
        End Sub
     
        '-----------------RAJOUT-----------------
        Private selectedPointFA As PointF = Nothing
        Private positionA As Integer = 0
     
        Private selectedPointFB As PointF = Nothing
        Private positionB As Integer = 0
        '---------------------------------
        Private selectedDataPointA As New DataPoint
        Private selectedDataPointB As New DataPoint
        Private Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown
            selectedDataPointA = Nothing
            positionA = -1
            If e.Button = MouseButtons.Left Then
                Dim hitResultA As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResultA Is Nothing Then Return
                If hitResultA.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPointA = CType(hitResultA.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPointA.IsValueShownAsLabel = True
                    '-----------------MAJ POINTS-----------------
                    positionA = hitResultA.PointIndex
                    selectedPointFA = New PointF(selectedDataPointA.XValue, selectedDataPointA.YValues(0))
                End If
            End If
     
     
            selectedDataPointB = Nothing
            positionB = -1
            If e.Button = MouseButtons.Left Then
                Dim hitResultB As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResultB Is Nothing Then Return
                If hitResultB.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPointB = CType(hitResultB.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPointB.IsValueShownAsLabel = True
                    '-----------------MAJ POINTS-----------------
                    positionB = hitResultB.PointIndex
                        selectedPointFB = New PointF(selectedDataPointB.XValue, selectedDataPointB.YValues(1))
     
                End If
            End If
     
        End Sub
     
        Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
            If selectedDataPointA Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                '  X value from current cursor position
                Dim xValueA As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                xValueA = Math.Round(Math.Max(xValueA, Chart1.ChartAreas(0).AxisX.Minimum), 0)
                xValueA = Math.Round(Math.Min(xValueA, Chart1.ChartAreas(0).AxisX.Maximum), 0)
     
                '  Y value from current cursor position
                Dim yValueA As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                yValueA = Math.Round(Math.Max(yValueA, Chart1.ChartAreas(0).AxisY.Minimum), 0)
                yValueA = Math.Round(Math.Min(yValueA, Chart1.ChartAreas(0).AxisY.Maximum), 0)
     
     
                ' Update selected point X,Y value
     
                selectedDataPointA.XValue = xValueA
                'selectedDataPoint.XValue = -selectedDataPoint.XValue
                selectedDataPointA.YValues(0) = yValueA
     
                selectedPointFA = New PointF(selectedDataPointA.XValue, selectedDataPointA.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsA(positionA) = selectedPointFA
     
                ResumeLiaison()
     
                    ' Invalidate chart
                    Chart1.Invalidate()
                End If
     
            '-----------------------------------------------------------------------------------------
            If selectedDataPointB Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                '  X value from current cursor position
                Dim xValueB As Double = Chart1.ChartAreas(1).AxisX.PixelPositionToValue(e.X)
                xValueB = Math.Round(Math.Max(xValueB, Chart1.ChartAreas(1).AxisX.Minimum), 0)
                xValueB = Math.Round(Math.Min(xValueB, Chart1.ChartAreas(1).AxisX.Maximum), 0)
     
                '  Y value from current cursor position
                Dim yValueB As Double = Chart1.ChartAreas(1).AxisY.PixelPositionToValue(e.Y)
                yValueB = Math.Round(Math.Max(yValueB, Chart1.ChartAreas(1).AxisY.Minimum), 0)
                yValueB = Math.Round(Math.Min(yValueB, Chart1.ChartAreas(1).AxisY.Maximum), 0)
     
     
                ' Update selected point X,Y value
     
                selectedDataPointB.XValue = xValueB
                'selectedDataPoint.XValue = -selectedDataPoint.XValue
                selectedDataPointB.YValues(1) = yValueB
     
                selectedPointFB = New PointF(selectedDataPointB.XValue, selectedDataPointB.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsB(positionB) = selectedPointFB
     
                ResumeLiaison()
     
                ' Invalidate chart
                Chart1.Invalidate()
            End If
     
     
     
        End Sub
     
        Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseUp
            If selectedDataPointA Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPointA.IsValueShownAsLabel = False
                selectedPointFA = New PointF(selectedDataPointA.XValue, selectedDataPointA.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsA(positionA) = selectedPointFA
     
                ResumeLiaison()
     
                ' reset selected object
                selectedDataPointA = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
            End If
     
            '---------------------------------------------------------------------------------------------------
     
            If selectedDataPointB Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPointB.IsValueShownAsLabel = False
                selectedPointFB = New PointF(selectedDataPointB.XValue, selectedDataPointB.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsB(positionB) = selectedPointFB
     
                ResumeLiaison()
     
                ' reset selected object
                selectedDataPointB = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
            End If
     
     
        End Sub
     
        Private Sub ResumeLiaison()
     
            BindingSourceA.ResetBindings(True)
            BindingSourceA.Position = positionA
     
            BindingSourceB.ResetBindings(True)
            BindingSourceB.Position = positionB
     
        End Sub
     
        Private Sub BindingSource1_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingSourceA.PositionChanged
            txtIndexA.Text = BindingSourceA.Position.ToString
     
        End Sub
     
        Private Sub BindingSourceB_PositionChanged(sender As Object, e As EventArgs) Handles BindingSourceB.PositionChanged
     
            txtIndexB.Text = BindingSourceB.Position.ToString
     
        End Sub
    End Class
    Le build s’exécute (option Strict = OFF) et me créer bien ma 2ème serie avec mes points du canal B, en revanche dès que j'essaie de draguer un point, l'exe plante à la ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim xValueB As Double = Chart1.ChartAreas(1).AxisX.PixelPositionToValue(e.X)
    avec l’exception suivante :

    Une exception non gérée du type 'System.ArgumentOutOfRangeException' s'est produite dans mscorlib.dll
    Informations supplémentaires : L'index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection.



    Comment dois-je m'y prendre pour intégrer correctement ma 2ème série (puis par la suite ma 3ème et 4ème série) ?
    Merci pour vos futurs conseils et aides en espérant pouvoir finaliser un bout de code

  13. #13
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Un control Chart peut avoir plusieurs surfaces de dessin (ChartArea qui sont des bmp pouvant etre activés separement: visible ou non visible)

    De meme ,point important,un ChartArea dans un Control Chart peut supporter autant de series qu'on veut(dessinées sur un meme bmp à la fois donc activés simultanement)...

    Cette ligne de code pose donc probleme,puisque toutes tes courbes interactives devraient etre toutes sur Chart1.chartArea(0)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Dim xValueB As Double = Chart1.ChartAreas(1).AxisX.PixelPositionToValue(e.X)
    Il faut virer ce Chart1.ChartArea(1)....et remplacer par Chart1.ChartArea(0)

    Pour réutiliser le mémé code -drag drop souris-déjà donne ,il faut donc:
    - récupérer dans hitResult la série clique
    - lier BindingSource1 au List(Of PointF) approprie au série cliqué,moyennant une petite modification dans le code (voir code revu ci-après)....
    Ce qui fait que la liaison de données au BindingSource1 est active au 1er clic de souris....

    code revu avec 3 series et un seul BindingSource1:

    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
     
    Imports System.Windows.Forms.DataVisualization.Charting
    Public Class FormMultipleSeries
     
        Private APoints As New List(Of PointF)
        Private BPoints As New List(Of PointF)
        Private CPoints As New List(Of PointF)
        Private Sub FormMultipleSeries_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '-----------------prepare Chart-----------------
            PrepareChart()
            '-----------------prepare Data-----------------
            GetData()
     
     
     
            ''-----------------prepare Bindings-----------------
     
            ' VOIR le Sub BindControls
     
     
     
        End Sub
        Private Sub PrepareChart()
            '-----------------prepare series ----------------
            Me.Chart1.Series(0).Points.Clear()
            For i As Integer = 0 To Me.Chart1.Series.Count - 1
                Me.Chart1.Series(i).Points.Clear()
                Me.Chart1.Series(i).ChartType = SeriesChartType.Line
                Me.Chart1.Series(i).XValueMember = "X"
                Me.Chart1.Series(i).YValueMembers = "Y"
                Me.Chart1.Series(i).BorderWidth = 3
            Next
            For i As Integer = 0 To Me.Chart1.Series.Count - 1
                Dim serie As Series = Me.Chart1.Series(i)
                Select Case i
                    Case 0
                        serie.Name = "Series Points A"
                        serie.Color = Color.Black
                        serie.MarkerColor = Color.Red
                        serie.MarkerStyle = MarkerStyle.Circle
                        serie.MarkerSize = 3
                    Case 1
                        serie.Name = "Series Points B"
                        serie.Color = Color.Orange
                        serie.MarkerColor = Color.Magenta
                        serie.MarkerStyle = MarkerStyle.Square
                        serie.MarkerSize = 4
                    Case 2
                        serie.Name = "Series Points C"
                        serie.Color = Color.Purple
                        serie.MarkerColor = Color.LimeGreen
                        serie.MarkerStyle = MarkerStyle.Star5
                        serie.MarkerSize = 5
                End Select
            Next
            'Move legend to bottom and center
            Chart1.Legends(0).Docking = Docking.Bottom
            Chart1.Legends(0).Alignment = StringAlignment.Center
        End Sub
        Private Sub GetData()
            '-----------------APoints-----------------
            APoints.Clear()
            For x As Double = 0 To 100
                Dim y As Double = 50 * x
                APoints.Add(New PointF(x, y))
            Next
            Chart1.Series(0).Points.DataBind(APoints, "X", "Y", Nothing)
     
            '-----------------BPoints-----------------
            BPoints.Clear()
            For x As Double = 0 To 100
                Dim y As Double = 25 * x
                BPoints.Add(New PointF(x, y))
            Next
            Chart1.Series(1).Points.DataBind(BPoints, "X", "Y", Nothing)
     
            '-----------------CPoints-----------------
            CPoints.Clear()
            For x As Double = 0 To 100
                Dim y As Double = x ^ 2
                CPoints.Add(New PointF(x, y))
            Next
            Chart1.Series(2).Points.DataBind(CPoints, "X", "Y", Nothing)
            Chart1.DataBind()
        End Sub
        'MODIF DANS LE CODE
        Private Sub BindControls()
            If selectedSerie Is Chart1.Series(0) Then
                BindingSource1.DataSource = APoints
            ElseIf selectedSerie Is Chart1.Series(1) Then
                BindingSource1.DataSource = BPoints
            ElseIf selectedSerie Is Chart1.Series(2) Then
                BindingSource1.DataSource = CPoints
            End If
            ListBox1.DataSource = BindingSource1
     
            txtX.DataBindings.Clear()
            txtY.DataBindings.Clear()
            txtX.DataBindings.Add("Text", BindingSource1, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtY.DataBindings.Add("Text", BindingSource1, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
        End Sub
        '--------------SERIE CLIQUEE-------------------
        Private selectedSerie As Series = Nothing
        Private selectedPointF As PointF = Nothing
        Private position As Integer = 0
     
        Private selectedDataPoint As New DataPoint
        Private Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown
            selectedDataPoint = Nothing
            position = -1
            selectedSerie = Nothing
            If e.Button = MouseButtons.Left Then
                Dim hitResult As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResult Is Nothing Then Return
                If hitResult.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPoint = CType(hitResult.Object, DataPoint)
                    selectedSerie = hitResult.Series 'RECUPERER SERIE CLIQUEE
                    BindControls()
     
                    ' Show point value as label
                    selectedDataPoint.IsValueShownAsLabel = True
                    '-----------------MAJ POINTS-----------------
                    position = hitResult.PointIndex
                    selectedPointF = New PointF(selectedDataPoint.XValue, selectedDataPoint.YValues(0))
                End If
            End If
     
        End Sub
     
        Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                '  X value from current cursor position
                Dim xValue As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                xValue = Math.Max(xValue, Chart1.ChartAreas(0).AxisX.Minimum)
                xValue = Math.Min(xValue, Chart1.ChartAreas(0).AxisX.Maximum)
     
                '  Y value from current cursor position
                Dim yValue As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                yValue = Math.Max(yValue, Chart1.ChartAreas(0).AxisY.Minimum)
                yValue = Math.Min(yValue, Chart1.ChartAreas(0).AxisY.Maximum)
     
                ' Update selected point X,Y value
     
                selectedDataPoint.XValue = xValue
                selectedDataPoint.YValues(0) = yValue
     
                selectedPointF = New PointF(selectedDataPoint.XValue, selectedDataPoint.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                BindingSource1.List(position) = selectedPointF
     
     
                ResumeLiaison()
     
     
                ' Invalidate chart
                Chart1.Invalidate()
            End If
     
     
        End Sub
     
        Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseUp
            If selectedDataPoint Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPoint.IsValueShownAsLabel = False
                selectedPointF = New PointF(selectedDataPoint.XValue, selectedDataPoint.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                BindingSource1.List(position) = selectedPointF
                ResumeLiaison()
     
                ' reset selected object
                selectedDataPoint = Nothing
                selectedSerie = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
     
     
            End If
        End Sub
        Private Sub ResumeLiaison()
            BindingSource1.ResetBindings(True)
        End Sub
        Private Sub BindingSource1_PositionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingSource1.PositionChanged
            txtIndex.Text = BindingSource1.Position.ToString
        End Sub
    End Class
    Pour la sauvegarde de tes différentes listes de points,il faut voir du cote de BinaryFormatter(sérialisation binaire)
    bon code...

  14. #14
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Bonjour Mabrouki et encore merci pour ton retour.

    Après de nombreux tests avec ton nouvel exemple je n'obtiens qu'une seul série dans le chart (Series Points A) et le TxtIndex ne fonctionne plus quand je drag un point.

    Je suis donc reparti avec mon exemple plus haut en remplaçant sur tes conseils le : Chart1.ChartArea(0) de ma 2ème série et le draggage re-fonctionne
    Mon dernier soucis est donc "l'identification des points à une série" afin que je puisse récupérer les valeurs des points selon le point associer à sa série. Actuellement le TxtIdex récupère l'index de ma listebox mais peut importe la série, donc impossible d'identifier un point à une série.

    Est-il possible d'identifier par un radiobutton si un point dragué appartient à ma série A, B, C ou D ? (Par exemple si l'utilisateur déplace un point de la série C alors radiobutton_C.checked = true ?? Dans quel parti du code pourrai-je placer cela ? J'ai fais quelques tentative mais sans succès

    Cela me permettrai de placer les bonnes valeurs au bon endroit

    Par avance merci pour vos précieux conseils

  15. #15
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    Re
    Il en coute de rajouter un Label à ton Form et une ligne d code dans le sub BindControls()

    code .vb revu du Sub en question:
    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
     
    Private Sub BindControls()
            If selectedSerie Is Chart1.Series(0) Then
                BindingSource1.DataSource = APoints
     
            ElseIf selectedSerie Is Chart1.Series(1) Then
                BindingSource1.DataSource = BPoints
            ElseIf selectedSerie Is Chart1.Series(2) Then
                BindingSource1.DataSource = CPoints
            End If
            'ligne à rajouter
            Label1.Text = selectedSerie.Name
            ListBox1.DataSource = BindingSource1
     
            txtX.DataBindings.Clear()
            txtY.DataBindings.Clear()
            txtX.DataBindings.Add("Text", BindingSource1, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtY.DataBindings.Add("Text", BindingSource1, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
        End Sub
    bon code...

  16. #16
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Bonjour Mabrouki,

    Je pense ne pas avoir compris ton code même avec l'ajout d'un label je n'obtiens qu'une série dans le chart1 et le TxtIndex reste à 0 quand je drag un point :

    Nom : graph 1.jpg
Affichages : 902
Taille : 104,9 Ko


    Je m'y perd dans les architectures de tes 2 exemples

    Dans mon code ci-dessous est-il possible de récupérer le nom de la série du point que l'utilisateur est en train de dragger (dans un label11 ou textbox) ? à partir de là je me débrouillerai pour le reste :


    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
     
    Imports System.Windows.Forms.DataVisualization.Charting
     
    Public Class Form1
        Private pointsA As New List(Of PointF)
        Private pointsB As New List(Of PointF)
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
            GetData()
     
        End Sub
        Private Sub GetData()
     
            Dim rnd As New Random
     
            'Canal A
            pointsA.Add(New PointF(ParaH1_CA.Text, txt_valeur1CA.Text))
            pointsA.Add(New PointF(ParaH2_CA.Text, txt_valeur2CA.Text))
            pointsA.Add(New PointF(ParaH3_CA.Text, txt_valeur3CA.Text))
            pointsA.Add(New PointF(ParaH4_CA.Text, txt_valeur4CA.Text))
            pointsA.Add(New PointF(ParaH5_CA.Text, txt_valeur5CA.Text))
            pointsA.Add(New PointF(ParaH6_CA.Text, txt_valeur6CA.Text))
            pointsA.Add(New PointF(ParaH7_CA.Text, txt_valeur7CA.Text))
            pointsA.Add(New PointF(ParaH8_CA.Text, txt_valeur8CA.Text))
            pointsA.Add(New PointF(ParaH9_CA.Text, txt_valeur9CA.Text))
            pointsA.Add(New PointF(ParaH10_CA.Text, txt_valeur10CA.Text))
     
            BindingSourceA.DataSource = pointsA
     
            Chart1.Series(0).ChartType = SeriesChartType.Line
            Chart1.Series(0).XValueMember = "X"
            Chart1.Series(0).YValueMembers = "Y"
            Chart1.Series(0).BorderWidth = 2
     
            Chart1.Series(0).MarkerColor = Color.Blue
            Chart1.Series(0).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(0).MarkerSize = 18
            With Chart1.Series(0)
                .Name = "Canal A"
            End With
     
            'Move legend to bottom and center
            Chart1.Legends(0).Docking = Docking.Bottom
            Chart1.Legends(0).Alignment = StringAlignment.Center
     
            ' les Bindings
     
            Chart1.Series(0).Points.DataBind(BindingSourceA, "X", "Y", Nothing)
            Chart1.DataBind()
            ListBoxA.DataSource = BindingSourceA
     
     
     
            txtXA.DataBindings.Add("Text", BindingSourceA, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtYA.DataBindings.Add("Text", BindingSourceA, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
            '---------------------------------------------------------------------------------------------------
     
            'Canal B
            pointsB.Add(New PointF(ParaH1_CB.Text, txt_valeur1CB.Text))
            pointsB.Add(New PointF(ParaH2_CB.Text, txt_valeur2CB.Text))
            pointsB.Add(New PointF(ParaH3_CB.Text, txt_valeur3CB.Text))
            pointsB.Add(New PointF(ParaH4_CB.Text, txt_valeur4CB.Text))
            pointsB.Add(New PointF(ParaH5_CB.Text, txt_valeur5CB.Text))
            pointsB.Add(New PointF(ParaH6_CB.Text, txt_valeur6CB.Text))
            pointsB.Add(New PointF(ParaH7_CB.Text, txt_valeur7CB.Text))
            pointsB.Add(New PointF(ParaH8_CB.Text, txt_valeur8CB.Text))
            pointsB.Add(New PointF(ParaH9_CB.Text, txt_valeur9CB.Text))
            pointsB.Add(New PointF(ParaH10_CB.Text, txt_valeur10CB.Text))
     
            BindingSourceB.DataSource = pointsB
     
            Chart1.Series(1).ChartType = SeriesChartType.Line
            Chart1.Series(1).XValueMember = "X"
            Chart1.Series(1).YValueMembers = "Y"
            Chart1.Series(1).BorderWidth = 2
     
            Chart1.Series(1).MarkerColor = Color.Blue
            Chart1.Series(1).MarkerStyle = MarkerStyle.Circle
            Chart1.Series(1).MarkerSize = 18
            With Chart1.Series(1)
                .Name = "Canal B"
            End With
     
     
            ' les Bindings
     
            Chart1.Series(1).Points.DataBind(BindingSourceB, "X", "Y", Nothing)
            Chart1.DataBind()
            ListBoxB.DataSource = BindingSourceB
     
            txtXB.DataBindings.Add("Text", BindingSourceB, "X", True, DataSourceUpdateMode.OnPropertyChanged)
            txtYB.DataBindings.Add("Text", BindingSourceB, "Y", True, DataSourceUpdateMode.OnPropertyChanged)
     
        End Sub
     
        '-----------------RAJOUT-----------------
        Private selectedPointFA As PointF = Nothing
        Private positionA As Integer = 0
     
        Private selectedPointFB As PointF = Nothing
        Private positionB As Integer = 0
        '---------------------------------
        Private selectedDataPointA As New DataPoint
        Private selectedDataPointB As New DataPoint
        Private position As Integer = 0
        Private Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseDown
            selectedDataPointA = Nothing
            positionA = -1
            If e.Button = MouseButtons.Left Then
     
                Dim hitResultA As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResultA Is Nothing Then Return
                If hitResultA.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPointA = CType(hitResultA.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPointA.IsValueShownAsLabel = True
                    '-----------------MAJ POINTS-----------------
                    positionA = hitResultA.PointIndex
                    selectedPointFA = New PointF(selectedDataPointA.XValue, selectedDataPointA.YValues(0))
     
                End If
            End If
     
     
            selectedDataPointB = Nothing
            positionB = -1
            If e.Button = MouseButtons.Left Then
     
                Dim hitResultB As HitTestResult = Chart1.HitTest(e.X, e.Y)
                If hitResultB Is Nothing Then Return
                If hitResultB.ChartElementType = ChartElementType.DataPoint Then
                    selectedDataPointB = CType(hitResultB.Object, DataPoint)
     
                    ' Show point value as label
                    selectedDataPointB.IsValueShownAsLabel = True
                    '-----------------MAJ POINTS-----------------
                    positionB = hitResultB.PointIndex
                    selectedPointFB = New PointF(selectedDataPointB.XValue, selectedDataPointB.YValues(0))
     
                End If
            End If
     
        End Sub
     
        Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
            If selectedDataPointA Is Nothing Then Return
            If e.Button = MouseButtons.Left Then
     
                '  X value from current cursor position
                Dim xValueA As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                xValueA = Math.Round(Math.Max(xValueA, Chart1.ChartAreas(0).AxisX.Minimum), 0)
                xValueA = Math.Round(Math.Min(xValueA, Chart1.ChartAreas(0).AxisX.Maximum), 0)
     
                '  Y value from current cursor position
                Dim yValueA As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                yValueA = Math.Round(Math.Max(yValueA, Chart1.ChartAreas(0).AxisY.Minimum), 0)
                yValueA = Math.Round(Math.Min(yValueA, Chart1.ChartAreas(0).AxisY.Maximum), 0)
     
     
                ' Update selected point X,Y value
     
                selectedDataPointA.XValue = xValueA
                'selectedDataPoint.XValue = -selectedDataPoint.XValue
                selectedDataPointA.YValues(0) = yValueA
     
                selectedPointFA = New PointF(selectedDataPointA.XValue, selectedDataPointA.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsA(positionA) = selectedPointFA
     
                '  X value from current cursor position
                Dim xValueB As Double = Chart1.ChartAreas(0).AxisX.PixelPositionToValue(e.X)
                xValueB = Math.Round(Math.Max(xValueB, Chart1.ChartAreas(0).AxisX.Minimum), 0)
                xValueB = Math.Round(Math.Min(xValueB, Chart1.ChartAreas(0).AxisX.Maximum), 0)
     
                '  Y value from current cursor position
                Dim yValueB As Double = Chart1.ChartAreas(0).AxisY.PixelPositionToValue(e.Y)
                yValueB = Math.Round(Math.Max(yValueB, Chart1.ChartAreas(0).AxisY.Minimum), 0)
                yValueB = Math.Round(Math.Min(yValueB, Chart1.ChartAreas(0).AxisY.Maximum), 0)
     
     
                ' Update selected point X,Y value
     
                selectedDataPointB.XValue = xValueB
                'selectedDataPoint.XValue = -selectedDataPoint.XValue
                selectedDataPointB.YValues(0) = yValueB
     
                selectedPointFB = New PointF(selectedDataPointB.XValue, selectedDataPointB.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsB(positionB) = selectedPointFB
     
                ResumeLiaison()
     
                    ' Invalidate chart
                    Chart1.Invalidate()
                End If
     
        End Sub
     
        Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseUp
            If selectedDataPointA Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPointA.IsValueShownAsLabel = False
                selectedPointFA = New PointF(selectedDataPointA.XValue, selectedDataPointA.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsA(positionA) = selectedPointFA
     
                ResumeLiaison()
     
                ' reset selected object
                selectedDataPointA = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
            End If
     
            '---------------------------------------------------------------------------------------------------
     
            If selectedDataPointB Is Nothing Then Return
            If e.Button = MouseButtons.Right Then
     
     
                ' Hide point label
                selectedDataPointB.IsValueShownAsLabel = False
                selectedPointFB = New PointF(selectedDataPointB.XValue, selectedDataPointB.YValues(0))
     
                '-----------------MAJ POINTS-----------------
                pointsB(positionB) = selectedPointFB
     
                ResumeLiaison()
     
                ' reset selected object
                selectedDataPointB = Nothing
     
                ' Invalidate chart
                Chart1.Invalidate()
     
            End If
     
     
        End Sub
        Private Sub ResumeLiaison()
     
            BindingSourceA.ResetBindings(True)
            BindingSourceA.Position = positionA
     
            BindingSourceB.ResetBindings(True)
            BindingSourceB.Position = positionB
     
        End Sub
     
        Private Sub BindingSourceA_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingSourceA.PositionChanged
            txtIndexA.Text = BindingSourceA.Position.ToString
     
     
        End Sub
     
     
        Private Sub BindingSourceB_PositionChanged(sender As Object, e As EventArgs) Handles BindingSourceB.PositionChanged
     
            txtIndexB.Text = BindingSourceB.Position.ToString
     
        End Sub
    End Class

    Voici ce que cela donne avec mes 2 séries dans Chart1 :

    Nom : graph2.jpg
Affichages : 886
Taille : 121,0 Ko

  17. #17
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Bonjour à tous,

    Je me permet de faire un petit up sur la discussion, j'essaye toujours en vain de créer 4 séries en même temps dans mon Chart1 avec la possibilité de savoir si le point draguer en cours appartient à tel ou tel série, si vous avez des idées je suis preneur .

    Cordialement,

  18. #18
    Membre expert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2013
    Messages
    1 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 563
    Points : 3 404
    Points
    3 404
    Par défaut
    Pourrais-tu faire un petit récap d'où tu en es dans ton problème? Arrives-tu à générer les différentes séries?

  19. #19
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    ZenZitone : ce gus est totalement bourré et il en serait incapable !!!
    Résumée de la discussion :
    Question initiale du post :au départ c'était "dragguer" un point de donne P(X,Y) à la souris sur un Chart.Series...=> Solution donnée...

    Nouvelle question : récupérer le point P "draggué et son index" .Le point P devait être affiche dans un TextBox =>Solution donné : un BindingSource sur son List(Of Point)
    Nouvelle question : comment traiter plusieurs Séries de Points sur un même ChartArea...Solution donné : utiliser un unique BindingSource qui sera activé sur la Série cliqué au moment du "dragguage souris" ,un seul Listbox, et un seul TextBox...

    Le gogo, c'est en est un ,ne prends pas en compte cette solution pourtant simple (la dernière postée) et me rétorques qu'il veut utiliser autant de BindingSources et de contrôles (ListBox et TextBox) qu'il y a de Chart.Series ....ce qui est totalement débile ...
    J'en ai conclu que le gogo avait atteint sa limite et qu'il était inutile de poursuivre une discussion sans autre objet que de polluer le forum VB.Net
    bon courage !!!

  20. #20
    Nouveau membre du Club
    Homme Profil pro
    electricien
    Inscrit en
    Janvier 2013
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : electricien
    Secteur : Bâtiment

    Informations forums :
    Inscription : Janvier 2013
    Messages : 200
    Points : 34
    Points
    34
    Par défaut
    Citation Envoyé par ZenZiTone Voir le message
    Pourrais-tu faire un petit récap d'où tu en es dans ton problème? Arrives-tu à générer les différentes séries?

    Bonjour ZenZiTone,

    Comme indiqué du départ je cherche a créer 4 séries dans 1 seul Chart avec la possibilité de déplacer les points avec la souris et de récupérer les coordonnées de chaques points dans mes textbox.
    Chaque série possède 10 points donc pour 1 série j'ai 10 textbox pour l'axe des X et 10 textbox pour l'axe de Y afin de récuperer leurs coordonnées.
    Pourquoi des texbox pour récupérer les coordonnées ? -> parce que l'utilisateur doit pouvoir la modifier précisément avant de les envoyer. L'axe des Y étant de 0 à 4095, la souris ne permet pas de précision à n+1

    Avec l'aide de Mabrouki j'arrive donc a créer ces séries toutes en même temps sur 1 seul chart mais je ne sais pas récupérer l'information de : lorsque je drag un point je ne sais pas à quel série il appartient.
    Il faudrait que j'arrive simplement à dire que si je drag le point 5 (txtindex.text = 5) de la série A par exemple alors txtserieA5X.text = coordonnées X du point et txtserieA5Y.text = coordonnées Y du point

    J’essaye de comprendre les exemples de Mabrouki afin de les utiliser dans mon cas. Si je n'avais pas besoin d'aide je ne viendrais pas sur le forum qui à mon sens reste un forum d'échange.
    Merci de ne pas traiter les gens à la première difficulté qu'il rencontre, tout le monde n'a pas le science infuse comme Mabrouki . Je suis toujours resté courtois et polis donc je ne comprend pas cette réaction.

    Le dernier exemple donné ne donne que 1 série sur le Chart et non 3 (voir imprim écran) et la récupération dans le txtIndex ne fonctionne plus. Je ne comprend pas le "Select case" alors que je souhaites 4 séries affichées en même temps. C'est peut-être ultra simple pour Mabrouki mais pas pour moi.

    Je reste néanmoins preneur de solution afin de pouvoir identifier si un point appartient à tel ou tel série dans le but final de récupérer les coordonnées dans leur textbox appropriés avec pourquoi pas 1 seul listbox et 1 seul txtIdex ce qui serai effectivement + logique.
    Pour le moment les bribes d'exemples transmises par Mabrouki, je n'ai pas réussi à les scinder et à les exploiter au complet

    En résumé a l'heure actuel j'arrive a créer 2 série ou + sur le même chart, je redistribue les valeurs dans mes textbox avec un timer -> si txtindex_serieD = 1 alors txtXD1 = coordonnées X et txtYD1 = coordonnées Y.
    sauf que cette méthode ne différencie pas les points des séries

    Très cordialement,

Discussions similaires

  1. Réponses: 10
    Dernier message: 19/02/2014, 14h19
  2. [XL-2003] Graphique avec points clignotants
    Par logiclogic dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 11/08/2010, 23h05
  3. Création d'un graphique avec IReport
    Par juju05 dans le forum iReport
    Réponses: 1
    Dernier message: 02/03/2010, 15h49
  4. [XL-2007] Création d'un graphique avec consolidation des données
    Par alex75 dans le forum Excel
    Réponses: 2
    Dernier message: 24/08/2009, 18h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo