ZedGraphをボタンクリックで表示について
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2008-11-12 11:10
初めまして、ZedGraphとVB2008 Express Editionを使い ボタンを押した時にグラフを書こうとしております。
ZedGraphのHPからサンプル(Multi-Y Demo)を持ってきて、ボタンをクリックした所1回クリックするだけなら普通に表示されるのですが、ボタンを連続でクリックしますと、distanceの緑のバーとenergyの黒のバーが、どんどん増殖して最後にはグラフその物が消えてしまいます。 最初グラフ上部に表示してある 線の色と形の部分も増殖してたのですが、それはzgc.GraphPane.CurveList.Clear()を入れる事によって解決ました。 ボタンを連続クリックしても、distanceの緑のバーとenergyの黒のバーが増殖しないようにするには、どうしたら良いのでしょうか。 なにとぞご教授おねがいします。 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click zgc.GraphPane.CurveList.Clear() Dim myPane As GraphPane = zgc.GraphPane ' Set the titles and axis labels myPane.Title.Text = "Demonstration of Multi Y Graph" myPane.XAxis.Title.Text = "Time, s" myPane.YAxis.Title.Text = "Velocity, m/s" myPane.Y2Axis.Title.Text = "Acceleration, m/s2" ' Make up some data points based on the Sine function Dim vList As New PointPairList() Dim aList As New PointPairList() Dim dList As New PointPairList() Dim eList As New PointPairList() ' Fabricate some data values Dim i As Integer Dim time As Double, acceleration As Double, velocity As Double Dim distance As Double, energy As Double For i = 0 To 30 time = i acceleration = 2.0 velocity = acceleration * time distance = acceleration * time * time / 2.0 energy = 100.0 * velocity * velocity / 2.0 aList.Add(time, acceleration) vList.Add(time, velocity) eList.Add(time, energy) dList.Add(time, distance) Next i ' Generate a red curve with diamond symbols, and "Velocity" in the legend Dim myCurve As LineItem = myPane.AddCurve("Velocity", vList, Color.Red, SymbolType.Diamond) ' Fill the symbols with white myCurve.Symbol.Fill = New Fill(Color.White) ' Generate a blue curve with circle symbols, and "Acceleration" in the legend myCurve = myPane.AddCurve("Acceleration", aList, Color.Blue, SymbolType.Circle) ' Fill the symbols with white myCurve.Symbol.Fill = New Fill(Color.White) ' Associate this curve with the Y2 axis myCurve.IsY2Axis = True ' Generate a green curve with square symbols, and "Distance" in the legend myCurve = myPane.AddCurve("Distance", dList, Color.Green, SymbolType.Square) ' Fill the symbols with white myCurve.Symbol.Fill = New Fill(Color.White) ' Associate this curve with the second Y axis myCurve.YAxisIndex = 1 ' Generate a Black curve with triangle symbols, and "Energy" in the legend myCurve = myPane.AddCurve("Energy", eList, Color.Black, SymbolType.Triangle) ' Fill the symbols with white myCurve.Symbol.Fill = New Fill(Color.White) ' Associate this curve with the Y2 axis myCurve.IsY2Axis = True ' Associate this curve with the second Y2 axis myCurve.YAxisIndex = 1 ' Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = True ' Make the Y axis scale red myPane.YAxis.Scale.FontSpec.FontColor = Color.Red myPane.YAxis.Title.FontSpec.FontColor = Color.Red ' turn off the opposite tics so the Y tics don't show up on the Y2 axis myPane.YAxis.MajorTic.IsOpposite = False myPane.YAxis.MinorTic.IsOpposite = False ' Don't display the Y zero line myPane.YAxis.MajorGrid.IsZeroLine = False ' Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside myPane.YAxis.Scale.Max = 100 ' Enable the Y2 axis display myPane.Y2Axis.IsVisible = True ' Make the Y2 axis scale blue myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue ' turn off the opposite tics so the Y2 tics don't show up on the Y axis myPane.Y2Axis.MajorTic.IsOpposite = False myPane.Y2Axis.MinorTic.IsOpposite = False ' Display the Y2 axis grid lines myPane.Y2Axis.MajorGrid.IsVisible = True ' Align the Y2 axis labels so they are flush to the axis myPane.Y2Axis.Scale.Align = AlignP.Inside myPane.Y2Axis.Scale.Min = 1.5 myPane.Y2Axis.Scale.Max = 3 ' Create a second Y Axis, green Dim yAxis3 As New YAxis("Distance, m") myPane.YAxisList.Add(yAxis3) yAxis3.Scale.FontSpec.FontColor = Color.Green yAxis3.Title.FontSpec.FontColor = Color.Green yAxis3.Color = Color.Green ' turn off the opposite tics so the Y2 tics don't show up on the Y axis yAxis3.MajorTic.IsInside = False yAxis3.MinorTic.IsInside = False yAxis3.MajorTic.IsOpposite = False yAxis3.MinorTic.IsOpposite = False ' Align the Y2 axis labels so they are flush to the axis yAxis3.Scale.Align = AlignP.Inside Dim yAxis4 As New Y2Axis("Energy") yAxis4.IsVisible = True myPane.Y2AxisList.Add(yAxis4) ' turn off the opposite tics so the Y2 tics don't show up on the Y axis yAxis4.MajorTic.IsInside = False yAxis4.MinorTic.IsInside = False yAxis4.MajorTic.IsOpposite = False yAxis4.MinorTic.IsOpposite = False ' Align the Y2 axis labels so they are flush to the axis yAxis4.Scale.Align = AlignP.Inside yAxis4.Type = AxisType.Log yAxis4.Scale.Min = 100 ' Fill the axis background with a gradient myPane.Chart.Fill = New Fill(Color.White, Color.LightGoldenrodYellow, 45.0F) zgc.AxisChange() End Sub よろしくおねがいします [ メッセージ編集済み 編集者: sakura 編集日時 2008-11-12 11:12 ] [ メッセージ編集済み 編集者: sakura 編集日時 2008-11-12 11:13 ] |
|
投稿日時: 2008-11-21 09:12
「 zgc.GraphPane.CurveList.Clear() 」の下に
「 zgc.GraphPane.GraphObjList.Clear() 」を入れてみてください。 参考サイト 「NYまたの名をnEEtEr ZedGraphデータを毎回初期化 http://nyvector.blog65.fc2.com/blog-entry-18.html」 |
|
投稿日時: 2008-11-21 13:37
カセイさん お返事ありがとうございました。
教えてもらいました zgc.GraphPane.GraphObjList.Clear()を入れてみたのですが どうも うまくいきません>< ZedGraphのHPから zgc.MasterPane = new MasterPane() を見つけたのですが これだとグラフ自体が消えてエラーまで出てしまいます;; Clearで検索をかけたところ、 zgc.GraphPane.GraphObjList.Clear() zgc.GraphPane.CurveList.Clear() zgc.MasterPane = new MasterPane() しか引っかかりませんでした なにぶん 素人なので よくわからないのですが、私のzgc.GraphPane.GraphObjList.Clearの使い方が悪いだけなのかもしれません 紹介してもらいましたHPは 大変参考になりました ありがとうございます。 |
|
投稿日時: 2008-11-21 14:29
sakura様
グラフの中身が増えるのかと勘違いしておりました。 申し訳ありません。 対処方はまだわかりませんが 「 myPane.YAxisList.Add(yAxis3) 」 「 myPane.Y2AxisList.Add(yAxis4) 」 のコードにより増加しているようです。 「 myPane.Y2AxisList.Clear() 」 としますと、青のメモリまでなくなってしまいますので、 無理やりな方法と致しましてはif文を使用するといった方法が挙げられます。 当方でもZedGraphを使用していますので、もうしばらく検証してみたいと思います。 |
|
投稿日時: 2008-11-21 14:46
カセイ様
度々のご返答まことに、ありがとうございます 増えてる原因が myPane.YAxisList.Add(yAxis3) myPane.Y2AxisList.Add(yAxis4) このあたりと特定してもらったのは、とても助かります この辺をいじって 色々やってみたいと思います |
1