I am working on an ASP.net/C# application and I need to do the following:
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?
What I mean is this:
I am creating a chart dynamically in 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.
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({
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. Here is an example of rendering a control to a string using RenderControl. http://blogs.x2line.com/al/articles/859.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.