在一个文档中保存多个图表

时间:2014-05-22 15:48:35

标签: vb.net visual-studio-2010 charts

我正在寻找一种在一个文档中保存3个不同图表的方法。 我的程序会计算一些数据,这些数据将显示在3个不同的图表中 我有chart1,chart2和chart3 我找到了这个代码,它只是将1个图表保存为一个文档中的图像

01  ' Displays a SaveFileDialog so the user can save the Image
02         ' assigned to Button2.
03         Dim saveFileDialog1 As New SaveFileDialog()
04         saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif       Image|*.gif"
05         saveFileDialog1.Title = "Save an Image File"
06         saveFileDialog1.ShowDialog()
07   
08         ' If the file name is not an empty string open it for saving.
09         If saveFileDialog1.FileName <> "" Then
10             ' Saves the Image via a FileStream created by the OpenFile method.
11             Dim fs As System.IO.FileStream = CType _
12                (saveFileDialog1.OpenFile(), System.IO.FileStream)
13             ' Saves the Image in the appropriate ImageFormat based upon the
14             ' file type selected in the dialog box.
15             ' NOTE that the FilterIndex property is one-based.
16             Select Case saveFileDialog1.FilterIndex
17                 Case 1
18                     Chart1.SaveImage(fs, _
19                        System.Drawing.Imaging.ImageFormat.Jpeg)
20   
21                 Case 2
22                     Chart1.SaveImage(fs, _
23                        System.Drawing.Imaging.ImageFormat.Bmp)
24   
25                 Case 3
26                     Chart1.SaveImage(fs, _
27                        System.Drawing.Imaging.ImageFormat.Gif)
28             End Select

有没有人有其他建议通过点击我的vb.net程序中的按钮在一个文档上保存3个不同的图表?

1 个答案:

答案 0 :(得分:0)

您应该将每个图表写入文件:

Chart1.SaveImage(fs & 1, System.Drawing.Imaging.ImageFormat.Jpeg)
Chart2.SaveImage(fs & 2, System.Drawing.Imaging.ImageFormat.Jpeg)
Chart3.SaveImage(fs & 3, System.Drawing.Imaging.ImageFormat.Jpeg)

使用Graphics.DrawImage(http://msdn.microsoft.com/en-us/library/42807xh1.aspx_

从这些文件创建新图形

然后,您可以使用Image.Save(http://msdn.microsoft.com/en-us/library/9t4syfhh%28v=vs.110%29.aspx

将此图像汇编保存在一个文件中

玩得开心!