jovstaas Posted December 3, 2007 Report Share Posted December 3, 2007 Hi, I'm porting an old Fortran program (engineering application) which creates deflection charts as HP-files. An example of the old chart is attached.It seems to be fairly easy to plot the same deflections using ChartFX, but I also need to plot/draw the "bearing symbols" in the attached sample. These are some straight lines on top and botton of the deflection curve. I have marked them with a red rectangle in the example. Can I use GDI or similar to plot the "bearing symbols"? Quote Link to comment Share on other sites More sharing options...
maximop Posted December 3, 2007 Report Share Posted December 3, 2007 Yes, you can use GDI to draw on the chart. If you want to keep interactivity with the control, you need to use the chart's PrePaint and PostPaint events, respectively. You can alternatively export the chart to an image, draw on the image, and display the chart's image using a PictureBox; however, as you may already notice, this will be a static image. I think that your best bet will be to implement you code within the chart's PrePaint and PostPaint events but in any case, I am posting some code showing you how to do this exporting to an image: chart1.Export(FileFormat.Bitmap, "D:\\Temp\\ChartTest.bmp"); Bitmap bmp = new Bitmap(Image.FromFile("D:\\Temp\\ChartTest.bmp")); Bitmap b = new Bitmap(chart1.Width, chart1.Height);Graphics g = Graphics.FromImage((Image); g.DrawImage(bmp, 0, 0, chart1.Width, chart1.Height); g.DrawLine( Pens.Black, 100, 100, 75, 75);g.DrawString("This is a test", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, 25, 25); FileStream fs = new FileStream("D:\\Temp\\NewChart.bmp", FileMode.Create);b.Save(fs, ImageFormat.Bmp); fs.Close(); g.Dispose(); Quote Link to comment Share on other sites More sharing options...
jovstaas Posted December 4, 2007 Author Report Share Posted December 4, 2007 I tried the PrePaint event, but my line appears on the back side of the plotting area. If I draw a line from e.g. position (0,0) I can see the starting point of the line, but then it disappears under the plot area. How can I create a graphics object from the plot area? It is important for me to keep the interactivity with the chart. Example code: Graphics g = chart1.CreateGraphics();Pen pen = new Pen(Color.Red); pen.Width = 10; g.DrawLine(pen, 0, 0, chart1.Width, chart1.Height); pen.Dispose(); g.Dispose(); Quote Link to comment Share on other sites More sharing options...
Frank Posted December 4, 2007 Report Share Posted December 4, 2007 You must use the PostPaint event instead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.