10-24-2006 04:22 PM
10-27-2006 06:45 PM
10-30-2006 11:00 AM
public partial class Form1 : Form { private ScatterPlot _plot; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Random rnd = new Random(); Listx = new List (); List y = new List (); for (int i = 0; i < 210000; i++) { x.Add(i); y.Add(rnd.NextDouble()); } _plot = new ScatterPlot(xAxis1, yAxis1); scatterGraph1.Plots.Add(_plot); _plot.PlotXY(x.ToArray(), y.ToArray()); } private void button2_Click(object sender, EventArgs e) { if (_plot != null) { scatterGraph1.Plots.Remove(_plot); _plot.Dispose(); _plot = null; } GC.Collect(); GC.WaitForPendingFinalizers(); } }
10-31-2006 11:24 AM
Calling Dispose() seems to work. I was already clearing the plots, but I was not calling Dispose().
Thanks,
Mike
10-31-2006 11:59 AM
breeve,
I had a question for you. What kind of performance do you get plotting 210000 points on a plot? We had such bad performance we had to go back to the ActiveX control.
Scott
10-31-2006 02:54 PM
11-02-2006 11:52 AM
SpeedPlot
Now, I was curious if I could make that time faster by not copying the data. When you call ScatterPlot.PlotXY, all your data is copied to an internal buffer. We do that to maintain the integrity of the plotted data as well as to support charting. I created a SpeedPlot object in the code below. This keeps a reference to the data and maps and draws the points itself, keeping the same timing process as above the following times where obtained:
public partial class Form1 : Form { private SpeedPlot _plot; public Form1() { InitializeComponent(); _plot = new SpeedPlot(new Range(0, 210000), new Range(0, 1), xAxis1, yAxis1); scatterGraph1.Plots.Add(_plot); } private void button1_Click(object sender, EventArgs e) { Random rnd = new Random(); Listx = new List (); List y = new List (); for (int i = 0; i < 210000; i++) { x.Add(i); y.Add(rnd.NextDouble()); } double[] xData = x.ToArray(); double[] yData = y.ToArray(); Stopwatch watch = Stopwatch.StartNew(); //switch line below to _plot from scatterGraph1 to test NoCopyPlot. scatterGraph1.PlotXY(xData, yData); //_plot.PlotData(xData, yData); watch.Stop(); textBox1.Text = watch.Elapsed.TotalSeconds.ToString(); } private class SpeedPlot : ScatterPlot { private double[] _xData; private double[] _yData; public SpeedPlot(Range xRange, Range yRange, XAxis xAxis, YAxis yAxis) : base(xAxis, yAxis) { XAxis.Mode = AxisMode.Fixed; YAxis.Mode = AxisMode.Fixed; XAxis.Range = xRange; YAxis.Range = yRange; } public void PlotData(double[] xData, double[] yData) { _xData = xData; _yData = yData; //Need to redraw new points. Invalidate(); } protected override void OnBeforeDraw(BeforeDrawXYPlotEventArgs e) { base.OnBeforeDraw(e); if (_xData != null && _yData != null) { PointF[] points = MapDataPoints(e.Bounds, _xData, _yData); using (Pen pen = new Pen(LineColor)) e.Graphics.DrawLines(pen, points); e.Cancel = true; } } } }
11-03-2006 09:48 AM
12-03-2006 06:43 AM
12-04-2006 10:24 AM