Reputation: 221
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
Upvotes: 1
Views: 752
Reputation: 18051
To achieve what you are trying to do, I can suggest two approaches.
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);
}
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.
Upvotes: 1