0

I am currently using:

chart.SaveImage(exportData.FileName.ToString(),System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Png);

to save a chart in a windows form as a .png file. Currently running into the issue that the chart is lacking axes and a title, etc. The images show the graph with data in Visual Studio and the saved image. As you can see, I am missing the axes and title in the saved image. Any help would be appreciated. Thank you.

Graph in visual studio: Graph in visual studio

Graph exported through SaveImage: Graph exported through SaveImage 2

Kcoder
  • 3,422
  • 4
  • 37
  • 56
MCollett
  • 23
  • 4

1 Answers1

1

I think you can use DrawToBitmap method. You also be able to add custom drawings and text on your chart canvas:

using (Bitmap im = new Bitmap(chart1.Width, chart1.Height))
{                
    chart1.DrawToBitmap(im, new Rectangle(0, 0, chart1.Width, chart1.Height));
    using (Graphics gr = Graphics.FromImage(im))
    {
        gr.DrawString("Test", 
            new Font(FontFamily.GenericSerif, 10, FontStyle.Bold), 
            new SolidBrush(Color.Red), new PointF(10, 10));
    }
    im.Save(path);                                    
}

This code is producing that image: enter image description here