1

I'm trying to make a program that will read some values, analyze them and plot the result. I can't get the plot thing to work though, which probably is due to faulty parameters being sent in to my plot class.

This is what I have in my Form class:

    private void FileButton_Click(object sender, EventArgs e)
    {
        OpenFileDialog ReadFileDialog = new OpenFileDialog();

        if (ReadFileDialog.ShowDialog() == DialogResult.OK)
        {
            ReadFile Acceleration = new ReadFile();

            if (PlotResultCheckbox.Checked)
            {
                PlotClass PlotResult = new PlotClass(); 
                //The FormClass being the class I'll call to plot from various part of my program

                PlotResult.FFTPlot();
            }

        }
     }


    private void FFTPlotWindow_Load(object sender, EventArgs e)
    {
          //Don't really know what to put here but this is my Plot-window anyway
    }

What parameters, besides the obvious ones with the data I shall plot, should I pass to my Plot class? Should I make FFTPlotWindow public?

Thanks in advance Axel

user2950764
  • 211
  • 4
  • 13
  • I think the answer is here :http://stackoverflow.com/questions/6614801/generating-and-saving-zedgraph-plots-without-showing-on-forms – Larry Nov 16 '13 at 11:36
  • @Laurent it might be! I still can't figure out exactly how though, since I still want to plot the graph in my form. When I create a class and method for it, it doesn't seem to be able to interact or even find my ZedGraph "window" in my form. Doing it public doesn't help either, so I need to know what parameters to pass to and from the form in order to be able to plot the result. Sorry if I wasn't clear about that earlier. – user2950764 Nov 16 '13 at 12:53
  • I don't understand the role of the PlotClass. Does it hold the data that needs to be plot? What is the FFTPlot() method supposed to do? – Larry Nov 16 '13 at 14:46
  • @Laurent Oh I see that I didn't mention it in the first post. The PlotClass is a class where I've collected all the plot methods (that is, a method for plotting frequency domain/FFT, time domain and some statistics). All the FFTPlot() is supposed to do is take the input data (two lists or arrays) with the data and make a plot in the Form. I can't get the PlotClass to access the ZedGraph window in my Form though, even though I've tried setting all to public. – user2950764 Nov 16 '13 at 15:29

1 Answers1

1

To achieve what you are trying to do, I can suggest two approaches.

  • Make the PlotClass interact with ZedGraph:

In this case, the PlotClass should be aware about it .

You can specify a reference to your ZedGraph control in the FFTPlot method that is supposed to plot the graph.

public class PlotClass
{
    ...

    public void FFTPlot(ZedGraphControl zgc)
    {   
        // Build the point list and attach it to a new curve

        GraphPane myPane = zgc.GraphPane;
        var list = new PointPairList();

        // Your code to add the points
        // ...

        var myCurve = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.None);
        zgc.AxisChange();
        zgc.Invalidate();
    }
}

Then :

if (PlotResultCheckbox.Checked)
{
    PlotClass PlotResult = new PlotClass(); 
    PlotResult.FFTPlot(zedGraphControl1);
}
  • The other approach (I would recommend) is to let your Form responsible to handle the ZedGraph control, using data exposed by the PlotClass. By this way, the PlotClass will remain independant from any graphic concerns.

So :

if (PlotResultCheckbox.Checked)
{
    PlotClass PlotResult = new PlotClass(); 

    GraphPane myPane = zedGraphControl1.GraphPane;
    var list = new PointPairList();

    // Your code to add the points using a property exposed by PlotResult
    // ...

    var myCurve = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.None);
    zedGraphControl1.AxisChange();
    zedGraphControl1.Invalidate();
}

Regardless the approach you decide, the ZedGraph wiki will be very helpful.

Larry
  • 17,605
  • 9
  • 77
  • 106
  • It works, thanks a lot! The reason I didn't want to do it the second way that you'd prefer is that I'll call this function in many parts of the program and don't want to write the code many times (for obvious reasons). Anyway, again many thanks for your help! – user2950764 Nov 17 '13 at 13:16