【问题标题】:Using MSChart in .net environment within a service在服务中的 .net 环境中使用 MSChart
【发布时间】:2012-06-02 15:28:23
【问题描述】:

有没有办法在服务(WCF/restful 服务)中使用 .NET 的 MSChart?要求是应该托管一个生成图表并将图表图像返回给调用应用程序的服务。调用应用程序应调用 Web 服务方法。没有网页可以嵌入 MSCHART 控件。

【问题讨论】:

    标签: .net wcf rest service mschart


    【解决方案1】:

    您可以在代码中生成图表,然后将图表保存到流中。然后将流返回给调用者。见http://msdn.microsoft.com/en-us/library/dd456181.aspx

    【讨论】:

      【解决方案2】:

      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);
               .
               .
               .
      

      【讨论】:

        猜你喜欢
        • 2014-05-02
        • 1970-01-01
        • 1970-01-01
        • 2019-09-07
        • 1970-01-01
        • 2019-01-17
        • 2012-02-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多