水晶报告中的 MS 图表

发布于 2024-11-24 13:36:07 字数 125 浏览 1 评论 0原文

是否可以在以适合打印的分辨率呈现的水晶报告中包含 ms Chart asp.net 控件的图表图像?

我的网站显示了一个 mschart,我希望在我的水晶报告中使用相同的图表,以便客户可以打印它。我不想使用水晶报告图表。

Is is possible to include the chart image of ms chart asp.net control in crystral reports rendered in a resolution suitable for print?

My website shows an mschart and i want that same chart in my crystal report so the client can print it. I don't want to use the crystal reports chart.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

汹涌人海 2024-12-01 13:36:07

我正在做类似的事情 - 使用 ms Chart 创建图表,将其与其他 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);
}

I'm doing something similar - creating a chart with ms chart, rendering it on a webpage, along with other html markup (data tables), and then the user can export to PDF or Excel. To do this, and retain the same chart image, my code saves the chart on the server as a .png image, then if the user wants to export the page, my code is calling that image in the export document (either pdf or excel) and displaying it with an tag.

This is the relevant code that does the save of the chart to the server:

// 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);
}
℉服软 2024-12-01 13:36:07

当您将 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 x 3 = 288dpi,打印时看起来更好。

When you save an MS chart as an image it always comes out at 96dpi, which isn't really great if you want to print it - should be more like 300dpi.

A simple workaround is to temporarily increase the chart size before calling 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;

This results in an image 3 times the size of the original. When shrunk to 1/3 of its size, it will have 96 x 3 = 288dpi, which looks a lot nicer when printed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文