有没有办法在服务中使用.NET的MSChart(WCF / restful services)?要求是托管服务以生成图表并将图表图像返回给调用应用程序。调用应用程序应调用Web服务方法。没有嵌入MSCHART控件的网页。
答案 0 :(得分:0)
您可以在代码中生成图表,然后将图表保存到流中。然后将流返回给调用者。见http://msdn.microsoft.com/en-us/library/dd456181.aspx
答案 1 :(得分: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);
.
.
.