简体   繁体   English

将Chart控件渲染为html字符串以追加div

[英]Render Chart control into html string to append div

I am working on an ASP.net/C# application and I need to do the following: 我正在使用ASP.net/C#应用程序,需要执行以下操作:

My question is how can I render a Chart control (the one that comes with the .net4) created dynamically in C# to and HTML string? 我的问题是如何呈现在C#和HTML字符串中动态创建的Chart控件(.net4附带的控件)?

What I mean is this: 我的意思是:

I am creating a chart dynamically in C# 我正在C#中动态创建图表

  //CREATE THE CHART
    Chart Chart1 = new Chart();

  //BIND THE DATA TO THE CHART
    Chart1.Series.Add(new Series());
    Chart1.Series[0].Points.DataBindXY(xName, yVal);

  //SET THE CHART TYPE TO BE PIE
    Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;
    Chart1.Series[0]["PieLabelStyle"] = "Outside";
    Chart1.Series[0]["PieStartAngle"] = "-90";


  //ADD A PLACE HOLDER CHART AREA TO THE CHART
  //SET THE CHART AREA TO BE 3D
    Chart1.ChartAreas.Add(new ChartArea());
    Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;

  //ADD A PLACE HOLDER LEGEND TO THE CHART
  //DISABLE THE LEGEND
    Chart1.Legends.Add(new Legend());
    Chart1.Legends[0].Enabled = false;

Then I want to Render it as HTML string and return it. 然后,我想将其渲染为HTML字符串并返回。

The reason I want this is because I am using AJAX Jquery to call the function that will get the chart as an HTMl string and append it to the 'ChartDiv' div element, in order to display it as a chart 我想要这个的原因是因为我正在使用AJAX Jquery调用将图表作为HTMl字符串并将其附加到'ChartDiv'div元素的函数,以便将其显示为图表

        $.ajax({
            type: "POST",
            url: "Service/RPCWebService.asmx/GetHTMLRenderForCountry",
            dataType: "json",
            async: true,
            data: "{'CountryCode':'" + countryCode + "'}",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                $("#ChartDiv").append(data.d);

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });

Thanks a lot for any help 非常感谢您的帮助

Take a look at the RenderControl method of the chart control. 看一下图表控件的RenderControl方法。 Here is an example of rendering a control to a string using RenderControl. 这是使用RenderControl将控件呈现为字符串的示例。 http://blogs.x2line.com/al/articles/859.aspx http://blogs.x2line.com/al/articles/859.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM