3

I wonder, is it possible to create vertical marker in zedgraph?
I want to render all chart points and make vertical marker as indicator of current position.

fat
  • 6,435
  • 5
  • 44
  • 70

2 Answers2

4

On a previous project, I used the following code to get that kind of effect.

int i = myPane.AddYAxis("");
myPane.YAxisList[i].Color = Color.Orange;
myPane.YAxisList[i].Scale.IsVisible = false;
myPane.YAxisList[i].MajorTic.IsAllTics = false;
myPane.YAxisList[i].MinorTic.IsAllTics = false;
myPane.YAxisList[i].Cross = pointOnXAxisThatIWantToMark;

In this case I add two axis to mark certain limits on my graph.

enter image description here

Community
  • 1
  • 1
JonC
  • 978
  • 2
  • 7
  • 28
  • Note that if you add labels (axis.Title.Text = "..."), 2+ of these lines will make a mysterious empty space on the left side of the Y axis (more space for each of these lines). But without labels, it is fine. – Curtis Yallop Aug 16 '13 at 20:54
  • Note that in ZedGraph v2.0 you set the scale visibility and IsAllTics on the axis object: yAxis.IsScaleVisible = false; yAxis.IsAllTics = false; You can also set the width of the line using: yAxis.TicPenWidth = 2; – salle55 Feb 02 '14 at 22:21
1

You can set the SymbolType of your curve to SymbolType.VDash.

For example, to set the symbol for a LineItem, you can either do it directly in the constructor (curve1 in the source code below), or you can customize it before assigning it to the curve (curve2).

This code:

var curve1 = new LineItem(null, new[] { 0.1, 0.5, 0.9 }, 
             new[] { 0.8, 0.3, 0.1 }, Color.Blue, SymbolType.VDash);
zedGraphControl1.GraphPane.CurveList.Add(curve1);

var curve2 = new LineItem(String.Empty)
    {
        Points = new PointPairList(
                 new[] { 0.1, 0.5, 0.9 }, new[] { 0.2, 0.5, 0.9 }),
        Color = Color.Red,
        Symbol = new Symbol(SymbolType.VDash, Color.Black) 
                 { Size = 20f, Border = new Border(Color.Black, 6f)}
    };
zedGraphControl1.GraphPane.CurveList.Add(curve2);

produces the following graph:

Non-customized and customized markers

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • I did not read thoroughly enough the first time and used a horizontal marker. Hopefully the vertical marker is more what you are asking for. Answer updated accordingly. – Anders Gustafsson Jun 28 '12 at 06:51