1

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

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

谢谢!

4

2 回答 2

1

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.

于 2010-04-03T08:26:54.333 回答
0

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

于 2010-04-03T08:37:04.103 回答