如何从 ASP.NET WebService 生成折线图?

发布于 2024-08-27 12:39:25 字数 89 浏览 3 评论 0原文

我的 Web 服务需要生成一些折线图,然后将其添加到流式传输到客户端的 PDF 报告中。

如何在 Web 服务中生成折线图?

谢谢!

My web service needs to do generate some line charts which will then be added to a PDF report that is streamed to the client.

How do I generate the line chart in the web service?

Thanks!

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

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

发布评论

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

评论(2

月亮邮递员 2024-09-03 12:39:25

如果您不想使用第三方控件,则可以使用 System.Drawing 命名空间。

  1. 创建正确大小的位图。最好使用 32bppargb,因为这是 GDI+ 内部使用的。
  2. 使用 Graphics.FromBitmap 从位图中获取图形对象
  3. 使用 Graphics.DrawLine 等在图形对象上绘制(所有方法都记录在图形对象上)
  4. 创建 MemoryStream 并将位图保存到 MemoryStream,然后您可以在 PDF 中使用它编写软件,或者只是将位图保存到磁盘(您需要授予 ASP.NET 权限才能执行此操作)

不要忘记在完成图形对象后立即处理它(使用块是最好的)

因为您正在使用在 Web 服务中的 GDI+ 中,您可能需要考虑使用单例模式来序列化请求以进行绘图。

If you don't want to use a third party control then you can use the System.Drawing namespace for this.

  1. Create a bitmap of the correct size. It is best to use 32bppargb because that is what GDI+ uses internally.
  2. Get a graphics object from the bitmap using Graphics.FromBitmap
  3. Draw on the graphics object using graphics.DrawLine etc (all the methods are documented on the graphics object)
  4. Create a MemoryStream and save the bitmap to the MemoryStream which you can then use in your PDF writing software, or simply save the bitmap to disk (you will need to give ASP.NET permissions to do this)

Dont forget to dispose the graphics object as soon as you have finished with it (a using block is best)

Because you are using GDI+ from within a web service, you may want to consider using the Singleton pattern to serialise requests to do the drawing.

许你一世情深 2024-09-03 12:39:25

在这里查看此网页

在 ASP.Net 中绘制折线图

然后,不要从 page_load 请求图表并在流中返回它,而是从您的 Web 服务功能之一返回它

编辑

离开并思考这个问题,然后灯泡熄灭了 - 另一种方式这样做(并且还将您从 GDI+ 代码中删除)将使用 GoogleCharts api。

例如 https://chart.apis.google.com/chart?cht=p3&chd=t:90,10&chs=250x100&chl=Overflow|Stack 呈现以下

alt text

折线图

http://code.google.com/apis/chart/docs/gallery/line_charts.html

另外,如果您还没有对 PDF 生成进行排序,请查看 iTextSharp 此处

Have a look at this webpage here

Drawing Line Charts in ASP.Net

Then instead of requesting the chart from your page_load and returning it in the stream, return it from one of your webservice functions

Edit

Went away and thought about this and then a lightbulb went off - another way of doing this (and also removing you from the GDI+ code) would be to use the GoogleCharts api.

For example https://chart.apis.google.com/chart?cht=p3&chd=t:90,10&chs=250x100&chl=Overflow|Stack renders the following

alt text

Line charts

http://code.google.com/apis/chart/docs/gallery/line_charts.html

Also, if you haven't sorted PDF generation yet, have a look at iTextSharp here

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