0

I use scatter plot in Zedgraph and trying to add a trend line over it. Now, I have two questions:

  1. How should I make sure that the textobj containing the equation and R2 of trendline is always on the upper left corner of the graph inside the graph box? I tried to fix it using the max and min of graph scale but so far I am unsuccessful.
  2. How can I remove the textobj from the graph?

I added the picture of my graph below.

Thanks for the help

enter image description here

Otiel
  • 18,404
  • 16
  • 78
  • 126
Amir
  • 625
  • 1
  • 11
  • 26
  • I am sorry I didn't add the code because it is very long and it is part of a very large program. – Amir Aug 17 '12 at 14:24

1 Answers1

3

You could probably try this,

    GraphPane pane;

    public Form1()
    {
        InitializeComponent();
        pane = zedGraphControl1.GraphPane;            
    }

    private void button_AddTxtObj_Click(object sender, EventArgs e)
    {            
        TextObj textEquation = new TextObj("Add your Text", pane.XAxis.Scale.Min+ (3*(pane.XAxis.Scale.MinorStep)), pane.YAxis.Scale.Max-pane.YAxis.Scale.MinorStep);            
        pane.GraphObjList.Add(textEquation);
        zedGraphControl1.Refresh();
    }

    private void button_ClearTxtObj_Click(object sender, EventArgs e)
    {
        pane.GraphObjList.Clear();
        zedGraphControl1.Refresh();
    }

enter image description here

when you zoom in or zoom out, the text object remains same , so you need to add zoom event to update the text object location, 1) clear the textobject 2) use the above approach to find the x&y positions 3) redraw text object:

private void zedGraphControl1_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
    {

        // 1) clear the textobject
        // 2) use the above approach to find the x&y positions
        // 3) redraw the text object
    }

Hope it helps...:)

SanVEE
  • 2,009
  • 5
  • 34
  • 55