2012-05-09 37 views
1

我試圖更改Zed圖線上的破折號的長度。我想在實線之間有更大的差距。我的代碼C#Zedgraph更改線破折號的長度

例如

LineItem LineCurve = null 
LineCurve = ZedGraphControl.GraphPane.AddCurve("line1",PairPointListData, Color, Symbol); 
//now I want to change the dash settings 
LineCurve.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash; 
LineCurve.Line.StepType = StepType.ForwardStep; 
LineCurve.Line.DashOn = 1.0f;//Not sure what this floating point does 
LineCurve.Line.DashOff = 1.0f;//Also not sure 

我已經改變了短跑和關閉的價值,但我看不到任何明顯的。 感謝您提出任何建議/想法

回答

6

您的短劃線樣式必須設置爲「自定義」。請參閱: http://zedgraph.sourceforge.net/documentation/html/P_ZedGraph_LineBase_DashOff.htm

下面是一些示例代碼:

 double[] xvals = new double[100]; 
     double[] yvals = new double[100]; 

     for (double i = 0; i < xvals.Length; i++) 
     { 
      xvals[(int)i] = i/10; 
      yvals[(int)i] = Math.Sin(i/10); 
     } 

     var zgc = msGraphControl1.zedGraphControl1; 
     var lineItem = zgc.GraphPane.AddCurve("Custom", xvals, yvals, Color.Blue); 

     lineItem.Line.Style = DashStyle.Custom; 
     lineItem.Line.Width = 3; 
     lineItem.Line.DashOn = 5; 
     lineItem.Line.DashOff = 10; 

     //offset the next curve 
     for (int i = 0; i < xvals.Length; i++) 
     { 
      xvals[i] = xvals[i] + 0.5; 
      yvals[i] = yvals[i] + 0.05; 
     } 

     var lineItem2 = zgc.GraphPane.AddCurve("DashDotDot", xvals, yvals, Color.Red); 

     lineItem2.Line.Width = 3; 
     lineItem2.Line.Style = DashStyle.DashDotDot; 

     //offset the next curve 
     for (int i = 0; i < xvals.Length; i++) 
     { 
      xvals[i] = xvals[i] + 0.5; 
      yvals[i] = yvals[i] + 0.05; 
     } 

     var lineItem3 = zgc.GraphPane.AddCurve("Solid", xvals, yvals, Color.Black); 

     lineItem3.Line.Width = 3; 
     lineItem3.Line.Style = DashStyle.Solid; 


     zgc.AxisChange(); 
     zgc.Refresh(); 
+0

這是否總是反映在圖例? – Ashitakalax

+0

所以我在簡單的單線圖上試過你的代碼,它工作得很好,但是當我在混合虛線和實線的多線圖上嘗試它時。它不起作用,它只會顯示虛線而不是dashDotDot和其他。 – Ashitakalax

+1

是的,它反映在傳說中。 –