水晶报表中的MS图表
在适合打印的分辨率中呈现的水晶报表中是否可以包含ms图表asp.net控件的图表图像?水晶报表中的MS图表
我的网站显示一个mschart,我想在我的水晶报告中显示相同的图表,以便客户端可以打印它。我不想使用水晶报表图表。
我正在做类似的事情 - 用ms图创建一个图表,在网页上显示它以及其他html标记(数据表),然后用户可以导出为PDF或Excel。为了做到这一点,并保留相同的图表图像,我的代码将图表作为.png图像保存在服务器上,然后如果用户想要导出页面,我的代码会在导出文档中调用该图像(pdf或excel )并用标签显示它。
这是相关的代码,不会保存图表到服务器的:
// save the finished image to a folder, so the PDF can retrive it later
v_chart.SaveImage(context.Server.MapPath(String.Concat(@"charts\chartimage_", v_runtimeReportKey, "_", v_chartID, ".png")));
// output the finished image to the browser
context.Response.Clear();
context.Response.ContentType = "image/png";
// following works fine with IIS 7 (Windows 7, or 2008 Server)
//v_chart.SaveImage(context.Response.OutputStream, ChartImageFormat.Png);
// must use the following for IIS 6 (Windows 2003 Server)
using(MemoryStream v_stream = new MemoryStream()){
v_chart.SaveImage(v_stream, ChartImageFormat.Png);
v_stream.WriteTo(context.Response.OutputStream);
}
当您保存MS图表作为图像它总是在96DPI,这是不是真的,如果大出来你想打印它 - 应该更像300dpi。
一个简单的解决方法是在调用SaveImage()
之前临时增加图表大小。
var originalWidth = myChart.Width;
var originalHeight = myChart.Height;
myChart.Width *= 3;
myChart.Height *= 3;
myChart.SaveImage("path\to\imageFile", ChartImageFormat.Bmp);
myChart.Width = originalWidth;
myChart.Height = originalHeight;
这会导致图像大小为原来的3倍。当缩小到其1/3的尺寸时,它将具有96×3 = 288dpi,这在打印时看起来更好。
如果我理解正确,它实际上增加了图像的dpi? – Jeroen
不完全。在代码输出的图像中,dpi(每英寸点数)保持不变 - 图像只有3倍大。 –
我在考虑做类似的事情,谢谢。你知道印刷质量的任何内容,或者如果有办法将PNG保存为更高的分辨率? – Jeroen
关于IIS的事情真棒黑客。当我使用MSCharts作为处理程序时,它对我有效。 – iMatoria