Microsoft Chart Controls für Microsoft .NET Framework 3.5

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von Gaga.

    Microsoft Chart Controls für Microsoft .NET Framework 3.5

    Hallo,

    kann man das Chart Control für .net Framework 3.5 auch im Visual Studio 2005 nutzen? Ich suche nun schon seit geraumer Zeit ein Tool oder sonstiges zum erstellen eines ganz normalen Diagramms. Nix, wo ich mich durch ein 100 seitiges englisches Tutorial quälen muß oder aber versteckt was abdrücken soll. Einfach nur X & Y Achse mit Werten. So langsam bin ich am verzweifeln.
    Wenn die Zeit kommt in der man könnte, ist die vorrüber in der man kann.
    Hallo Gaga,

    ich kann dort keinen passenden Eintrag finden. Evtl. habe ich ja nicht alles installiert, was dazu gehört. Bis jetzt waren das "dotnetfx35setup","MSChart.exe" und "MSChartLP_deu.exe". Dann habe ich mir noch die VB-Samples installiert um mich einlesen zu können. Aber leider kann ich keinen Eintrag finden, aus dem ich entnehmen könnte das er zu zedGraph gehört und in die ToolBox gehört.

    Es tut mir leid, wenn ich da evtl. etwas schwerfällig bin. Aber so lange muß ich noch nicht unter dem Visual Studio 2005 arbeiten und habe auch keine großen Vorkentnisse gehabt. Aber dafür gibt es ja dieses prima Forum :D
    Wenn die Zeit kommt in der man könnte, ist die vorrüber in der man kann.
    ...ich bins mal wieder ?(

    Also nun hab ich soweit denk ich mal alles installiert, was mit dem Umgang von ZedGraph nötig sein sollte (als letztes die .dll fur 1.1 & 2.0). Trotzdem sieht es bei mir anders als in den Samples aus (siehe Anhang). Auch meckert mich wegen dem fehlenden Namespace bei Einfügen von Programmcode aus den Samples an. Irgend etwas stimmt doch da noch nicht.

    @ Gaga

    Kannst Du mir nicht evtl. mal etwas Code als Bsp. zeigen damit ich testen kann, ob noch etwas fehlt?

    Danke im vorrab für Deine Mühe!

    P.S. Wozu brauche ich Framework 3.5, wenn ich als .dll sowieso nur 1.1 und 2.0 laden kann?
    Bilder
    • Chart.JPG

      28,78 kB, 825×532, 289 mal angesehen
    Wenn die Zeit kommt in der man könnte, ist die vorrüber in der man kann.
    Ich hab eigentlich nur einen Import auf ZedGraph drin.
    P.S. Wozu brauche ich Framework 3.5, wenn ich als .dll sowieso nur 1.1 und 2.0 laden kann?
    Wenn du wirklich VB2005 verwendest, hast du das FW 3.5 ja sowieso nicht zur Verfügung, das gibts erst seit VB2008

    Beispiel:
    Code in Form1:

    VB.NET-Quellcode

    1. Imports ZedGraph
    2. Public Class Form1
    3. '// BarGraphBandDemo
    4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    5. Handles MyBase.Load
    6. FillList()
    7. Dim gpnInit As GraphPane = Me.zedGraph.GraphPane
    8. '// Einstelungen die normalerweise im Eigenschaftsfenster gemacht werden
    9. '// das PointValueEvent aktivieren
    10. Me.zedGraph.IsShowPointValues = True
    11. '// grundsätzlich das Scrollen einschalten
    12. Me.zedGraph.AutoScroll = True
    13. '// die horizontale Scrollbar anzeigen
    14. Me.zedGraph.IsShowHScrollBar = True
    15. '// ja, das ist ernst gemeint, noch sagen,
    16. '// dass wirklich gescrollt werden soll
    17. Me.zedGraph.IsAutoScrollRange = True
    18. '// Texte
    19. gpnInit.Title.Text = "Line Graph with Band Demo"
    20. gpnInit.XAxis.Title.Text = "Sequence"
    21. gpnInit.YAxis.Title.Text = "Temperature, C"
    22. '// beiger Hintergrund
    23. '// Fill the axis background with a color gradient
    24. gpnInit.Chart.Fill = New Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90.0F)
    25. '// Anzeigebereich
    26. '// Manually set the x axis range
    27. 'MsgBox(gpnInit.XAxis.Scale.MaxGrace)
    28. 'gpnInit.XAxis.Scale.MaxAuto = False
    29. gpnInit.XAxis.Scale.Min = 100
    30. gpnInit.XAxis.Scale.Max = 800
    31. gpnInit.YAxis.Scale.Min = 0
    32. gpnInit.YAxis.Scale.Max = 140
    33. '// gepunktelte Linien
    34. '// Display the Y axis grid lines
    35. gpnInit.YAxis.MajorGrid.IsVisible = True
    36. gpnInit.YAxis.MinorGrid.IsVisible = True
    37. '// Text "Optimal Range"
    38. '// Add a text item to label the highlighted range
    39. Dim textRange As TextObj = New TextObj("Optimal" & vbCrLf & "Range", 0.9, 0.4, _
    40. CoordType.PaneFraction, _
    41. AlignH.Right, AlignV.Center)
    42. textRange.FontSpec.Fill.IsVisible = False
    43. textRange.FontSpec.Border.IsVisible = False
    44. textRange.FontSpec.IsBold = True
    45. textRange.FontSpec.IsItalic = True
    46. gpnInit.GraphObjList.Add(textRange)
    47. '// Grünen Bereich machen
    48. RedrawGreenBox()
    49. '// Ansicht aktualisieren
    50. '// tell the control to rescale itself
    51. Me.zedGraph.AxisChange()
    52. '// redraw the entire form
    53. Me.zedGraph.Invalidate()
    54. End Sub
    55. Private Function zedGraph_PointValueEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal pane As ZedGraph.GraphPane, ByVal curve As ZedGraph.CurveItem, ByVal iPt As Integer) As String _
    56. Handles zedGraph.PointValueEvent
    57. Dim ptpCurrent As PointPair = curve(iPt)
    58. Return curve.Label.Text & vbCrLf & " Y: " + ptpCurrent.Y.ToString("f2") & vbCrLf & " X: " + ptpCurrent.X.ToString("f1")
    59. End Function
    60. Private Sub zedGraph_ScrollEvent(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) _
    61. Handles zedGraph.ScrollEvent
    62. RedrawGreenBox()
    63. End Sub
    64. Private Sub zedGraph_ZoomEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal oldState As ZedGraph.ZoomState, ByVal newState As ZedGraph.ZoomState) _
    65. Handles zedGraph.ZoomEvent
    66. RedrawGreenBox()
    67. End Sub
    68. Private Sub RedrawGreenBox()
    69. Dim gpnInit As GraphPane = Me.zedGraph.GraphPane
    70. If gpnInit.GraphObjList.Count > 1 Then gpnInit.GraphObjList.RemoveAt(1)
    71. Dim boxGreen As BoxObj
    72. With gpnInit.XAxis.Scale
    73. boxGreen = New BoxObj(.Min, 100, .Max - .Min, 30, Color.Empty, _
    74. Color.FromArgb(150, Color.LightGreen))
    75. End With
    76. boxGreen.Fill = New Fill(Color.White, Color.FromArgb(200, Color.LightGreen), 45.0F)
    77. boxGreen.ZOrder = ZOrder.F_BehindGrid
    78. gpnInit.GraphObjList.Add(boxGreen)
    79. End Sub
    80. Private Sub btnSymbols_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    81. Handles btnSymbols.Click
    82. Dim gpnInit As GraphPane = Me.zedGraph.GraphPane
    83. Dim crvLine As LineItem
    84. For Each crvItem As CurveItem In gpnInit.CurveList
    85. crvLine = CType(crvItem, LineItem)
    86. crvLine.Symbol.IsVisible = Not crvLine.Symbol.IsVisible
    87. Next crvItem
    88. Me.zedGraph.Invalidate()
    89. End Sub
    90. Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    91. Handles btnAdd.Click
    92. Dim gpnInit As GraphPane = Me.zedGraph.GraphPane
    93. Dim booSymbol As Boolean
    94. If gpnInit.CurveList.Count > 0 Then
    95. booSymbol = CType(gpnInit.CurveList.Item(0), LineItem).Symbol.IsVisible
    96. Else
    97. booSymbol = True
    98. End If
    99. For Each cliAdd As CurveListItem In Me.lvwKurven.SelectedItems
    100. Dim crvKurve As LineItem = gpnInit.AddCurve(cliAdd.Text, cliAdd.x, cliAdd.y, cliAdd.ForeColor)
    101. crvKurve.Symbol.Fill = New Fill(Color.White)
    102. crvKurve.Symbol.IsVisible = booSymbol
    103. If gpnInit.CurveList.Count = 1 Then Me.zedGraph.AxisChange()
    104. Next cliAdd
    105. Me.zedGraph.Invalidate()
    106. End Sub
    107. Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    108. Handles btnDel.Click
    109. Dim gpnInit As GraphPane = Me.zedGraph.GraphPane
    110. For Each cliDel As CurveListItem In Me.lvwKurven.SelectedItems
    111. For Each crvKurve As LineItem In gpnInit.CurveList
    112. If crvKurve.Label.Text = cliDel.Text Then
    113. gpnInit.CurveList.Remove(crvKurve)
    114. Exit For
    115. End If
    116. Next crvKurve
    117. Next cliDel
    118. Me.zedGraph.Invalidate()
    119. End Sub
    120. Private Sub FillList()
    121. Dim x() As Double = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600}
    122. Dim y() As Double = {100, 115, 75, 22, 98, 40, 10, 50, 60, 100, 110, 90, 70, 75, 80, 60}
    123. Dim y2() As Double = {90, 100, 95, 35, 80, 35, 35, 40, 45, 90, 99, 82, 65, 90, 80, 50}
    124. Dim y3() As Double = {80, 110, 65, 15, 54, 67, 18, 25, 36, 84, 74, 80, 70, 65, 61, 45}
    125. Dim cliNew As New CurveListItem("Curve 1", Color.Red)
    126. cliNew.x = x
    127. cliNew.y = y
    128. Me.lvwKurven.Items.Add(cliNew)
    129. cliNew = New CurveListItem("Curve 2", Color.Blue)
    130. cliNew.x = x
    131. cliNew.y = y2
    132. Me.lvwKurven.Items.Add(cliNew)
    133. cliNew = New CurveListItem("Curve 3", Color.Green)
    134. cliNew.x = x
    135. cliNew.y = y3
    136. Me.lvwKurven.Items.Add(cliNew)
    137. End Sub
    138. Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
    139. Dim gpnInit As GraphPane = Me.zedGraph.GraphPane
    140. gpnInit.XAxis.Scale.Min += 15
    141. gpnInit.XAxis.Scale.Max += 25
    142. Me.zedGraph.Invalidate()
    143. RedrawGreenBox
    144. End Sub
    145. End Class
    146. Public Class CurveListItem : Inherits ListViewItem
    147. Public x() As Double
    148. Public y() As Double
    149. Public Sub New(ByVal Text As String, ByVal Color As Color)
    150. MyBase.Text = Text
    151. MyBase.ForeColor = Color
    152. End Sub
    153. End Class


    Code im Designer:
    (im Projektexplorer auf alle Dateien Anzeigen und dann unter Form1.VB die Form1.Designer.vb)

    VB.NET-Quellcode

    1. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    2. Partial Class Form1
    3. Inherits System.Windows.Forms.Form
    4. 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
    5. <System.Diagnostics.DebuggerNonUserCode()> _
    6. Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    7. If disposing AndAlso components IsNot Nothing Then
    8. components.Dispose()
    9. End If
    10. MyBase.Dispose(disposing)
    11. End Sub
    12. 'Wird vom Windows Form-Designer benötigt.
    13. Private components As System.ComponentModel.IContainer
    14. 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
    15. 'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
    16. 'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
    17. <System.Diagnostics.DebuggerStepThrough()> _
    18. Private Sub InitializeComponent()
    19. Me.components = New System.ComponentModel.Container
    20. Me.zedGraph = New ZedGraph.ZedGraphControl
    21. Me.btnSymbols = New System.Windows.Forms.Button
    22. Me.lvwKurven = New System.Windows.Forms.ListView
    23. Me.colKurve = New System.Windows.Forms.ColumnHeader
    24. Me.btnAdd = New System.Windows.Forms.Button
    25. Me.btnDel = New System.Windows.Forms.Button
    26. Me.btnTest = New System.Windows.Forms.Button
    27. Me.SuspendLayout()
    28. '
    29. 'zedGraph
    30. '
    31. Me.zedGraph.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
    32. Or System.Windows.Forms.AnchorStyles.Left) _
    33. Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    34. Me.zedGraph.AutoScroll = True
    35. Me.zedGraph.IsAutoScrollRange = True
    36. Me.zedGraph.IsShowHScrollBar = True
    37. Me.zedGraph.Location = New System.Drawing.Point(12, 12)
    38. Me.zedGraph.Name = "zedGraph"
    39. Me.zedGraph.ScrollGrace = 0
    40. Me.zedGraph.ScrollMaxX = 0
    41. Me.zedGraph.ScrollMaxY = 0
    42. Me.zedGraph.ScrollMaxY2 = 0
    43. Me.zedGraph.ScrollMinX = 0
    44. Me.zedGraph.ScrollMinY = 0
    45. Me.zedGraph.ScrollMinY2 = 0
    46. Me.zedGraph.Size = New System.Drawing.Size(472, 422)
    47. Me.zedGraph.TabIndex = 0
    48. '
    49. 'btnSymbols
    50. '
    51. Me.btnSymbols.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
    52. Me.btnSymbols.Location = New System.Drawing.Point(12, 440)
    53. Me.btnSymbols.Name = "btnSymbols"
    54. Me.btnSymbols.Size = New System.Drawing.Size(68, 23)
    55. Me.btnSymbols.TabIndex = 1
    56. Me.btnSymbols.Text = "Symbole"
    57. Me.btnSymbols.UseVisualStyleBackColor = True
    58. '
    59. 'lvwKurven
    60. '
    61. Me.lvwKurven.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    62. Me.lvwKurven.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colKurve})
    63. Me.lvwKurven.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None
    64. Me.lvwKurven.Location = New System.Drawing.Point(490, 12)
    65. Me.lvwKurven.Name = "lvwKurven"
    66. Me.lvwKurven.Size = New System.Drawing.Size(142, 199)
    67. Me.lvwKurven.TabIndex = 2
    68. Me.lvwKurven.UseCompatibleStateImageBehavior = False
    69. Me.lvwKurven.View = System.Windows.Forms.View.Details
    70. '
    71. 'colKurve
    72. '
    73. Me.colKurve.Text = ""
    74. '
    75. 'btnAdd
    76. '
    77. Me.btnAdd.Location = New System.Drawing.Point(490, 217)
    78. Me.btnAdd.Name = "btnAdd"
    79. Me.btnAdd.Size = New System.Drawing.Size(48, 24)
    80. Me.btnAdd.TabIndex = 3
    81. Me.btnAdd.Text = "Add"
    82. Me.btnAdd.UseVisualStyleBackColor = True
    83. '
    84. 'btnDel
    85. '
    86. Me.btnDel.Location = New System.Drawing.Point(544, 217)
    87. Me.btnDel.Name = "btnDel"
    88. Me.btnDel.Size = New System.Drawing.Size(48, 24)
    89. Me.btnDel.TabIndex = 4
    90. Me.btnDel.Text = "Del"
    91. Me.btnDel.UseVisualStyleBackColor = True
    92. '
    93. 'btnTest
    94. '
    95. Me.btnTest.Location = New System.Drawing.Point(490, 267)
    96. Me.btnTest.Name = "btnTest"
    97. Me.btnTest.Size = New System.Drawing.Size(87, 26)
    98. Me.btnTest.TabIndex = 5
    99. Me.btnTest.Text = "ScrollTest"
    100. Me.btnTest.UseVisualStyleBackColor = True
    101. '
    102. 'Form1
    103. '
    104. Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    105. Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    106. Me.ClientSize = New System.Drawing.Size(634, 475)
    107. Me.Controls.Add(Me.btnTest)
    108. Me.Controls.Add(Me.btnDel)
    109. Me.Controls.Add(Me.btnAdd)
    110. Me.Controls.Add(Me.lvwKurven)
    111. Me.Controls.Add(Me.btnSymbols)
    112. Me.Controls.Add(Me.zedGraph)
    113. Me.Name = "Form1"
    114. Me.Text = "Form1"
    115. Me.ResumeLayout(False)
    116. End Sub
    117. Friend WithEvents zedGraph As ZedGraph.ZedGraphControl
    118. Friend WithEvents btnSymbols As System.Windows.Forms.Button
    119. Friend WithEvents lvwKurven As System.Windows.Forms.ListView
    120. Friend WithEvents colKurve As System.Windows.Forms.ColumnHeader
    121. Friend WithEvents btnAdd As System.Windows.Forms.Button
    122. Friend WithEvents btnDel As System.Windows.Forms.Button
    123. Friend WithEvents btnTest As System.Windows.Forms.Button
    124. End Class

    Du brauchst jetzt eigentlich nur ein neues Projekt anlegen, die beiden Codeteile in die zwei Dateien kopieren und einen Verweis auf ZedGraph aufnehmen (Code ist VB2005)
    Hallo Gaga,

    erst einmal recht herzlichen Dank für das Projekt. Klappt sehr gut. :thumbsup: Hoffe Du hast nichts dagegen, wenn ich bei einem erneuten Problem diesen Thread hier noch mal aufgreife und mich damit hier im Forum noch mal melde?
    Wenn die Zeit kommt in der man könnte, ist die vorrüber in der man kann.
    Hallo Gaga,

    da wäre schon meine erste Frage (und hoffentlich auch die letzte): Auf der X-Achse möchte ich einen Tag von 0-24 Uhr darstellen. Die Meßpunkte sollten dann auch Uhrzeiten des Tages sein. Ausbauen will ich es dann, sofern es mir möglich ist, das man über 2 Monatskalender die Zeitspanne von - bis einstellen kann. Aber das wäre dann "nur" Nice to Have. Wichtiger wäre mir, die Uhrzeit auf der X-Ache zu haben. Hast Du da noch mal einen Tip für mich?
    Wenn die Zeit kommt in der man könnte, ist die vorrüber in der man kann.