开发者

How do I generate a line chart from an asp.net WebService?

My web service needs to do generate some line charts which will then be added to a PDF report that开发者_如何学Go is streamed to the client.

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

Thanks!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜