Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Printing a scattergraph with many points in C# takes along time

I have a scattergraph with 2 plots of approximately 25000 points each. I am trying to print the graph but it takes over a minute to print. I'm using the following code:

Rectangle bounds = new Rectangle(ev.MarginBounds.X, ev.MarginBounds.Y,
ev.MarginBounds.Width,
(int)ev.MarginBounds.Height/3);
scatterGraph1.Draw(new ComponentDrawArgs(ev.Graphics, bounds));

where ev is PrintPageEventArgs

Is there an alternative method for printing the graph that doesn't take so long?
0 Kudos
Message 1 of 2
(3,872 Views)
One thing that you could try is to draw the graph to an offscreen bitmap, then draw the bitmap all at once to the printer. For example:

private void OnPrintPage(object sender, PrintPageEventArgs e)
{
int width = e.MarginBounds.Width;
int height = e.MarginBounds.Height / 3;

using (Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppPArgb))
using (Graphics g = Graphics.FromImage(bmp))
{
Rectangle bounds = new Rectangle(0, 0, width, height);
scatterGraph1.Draw(new ComponentDrawArgs(g, bounds));

e.Graphics.DrawImage(bmp, e.MarginBounds.X, e.MarginBounds.Y);
}
}

Please try this and post a reply about how this worked out. Thanks.

- Elton
0 Kudos
Message 2 of 2
(3,872 Views)