Jump to content
Software FX Community

Drawing lines on chart


Recommended Posts



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"?


Link to comment
Share on other sites

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);


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);



Link to comment
Share on other sites

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);



Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...