2012-06-02 88 views
0

有什麼辦法可以在服務中使用.NET的MSChart(WCF/restful services)嗎?要求是應該託管一個服務來生成圖表並將圖表圖像返回給調用應用程序。調用應用程序應調用Web服務方法。沒有網頁來嵌入MSCHART控件。在.net環境中使用MSChart服務

回答

0

VB版..

<WebMethod()> _ 
     Public Function GetChart(ByVal param1 As String, ByVal width As Integer) As String 
      Dim ch As New Charting 
      Dim ds As DataSet = blablabla 
      Dim page As New Page() 
      Dim form As New HtmlForm() 
      form.Controls.Add(ch.buildChart(param1, ds, width)) 
      page.Controls.Add(form) 
      Dim textWriter As New IO.StringWriter() 
      HttpContext.Current.Server.Execute(page, textWriter, False) 
      Dim htmltxt As String = textWriter.ToString 
      Return Regex.Replace(htmltxt, "<[/]?(form)[^>]*?>", "", RegexOptions.IgnoreCase) 
    End Function 

一樣使用(jQuery的):

function GetChart(param1) { 
     var params = new Object(); 
     params.param1 = param1; 
     params.width = $(window).width() - 115; 
     $.ajax(
     { 
     type: "POST", 
     data: $.toJSON(params), 
     url: "WebService.asmx/GetChart", 
     dataType: "json", 
     contentType: "application/json", 
     complete: function (response) { 
     }, 
     success: function (response) { 
     $(divChart).html(response.d); 
     . 
     . 
     .