Please follow the code below.
I'm trying to generate a chart using the WebMethod and try to send the response (either the whole rendered output of RadChart or just the ChartImage.axd url) as a repsonse in an Ajax method.
How can I achieve? Or is this undoable?
| [System.Web.Services.WebMethod()] |
| public static string GetChart1() |
| { |
| Telerik.Web.UI.RadChart chart = new Telerik.Web.UI.RadChart(); |
| chart.ChartTitle.TextBlock.Text = "My title"; |
| chart.DefaultType = ChartSeriesType.Line; |
| chart.Appearance.ImageQuality = Telerik.Charting.Styles.ImageQuality.HighQuality; |
| ChartSeries data1 = new ChartSeries("Page Views", ChartSeriesType.Line); |
| data1.AddItem(100); |
| data1.AddItem(25); |
| data1.AddItem(500); |
| data1.AddItem(1000); |
| data1.AddItem(5000); |
| ChartSeries data2 = new ChartSeries("Hits", ChartSeriesType.Line); |
| data2.AddItem(50); |
| data2.AddItem(100); |
| data2.AddItem(300); |
| data2.AddItem(2000); |
| data2.AddItem(4000); |
| chart.Series.Add(data1); |
| chart.Series.Add(data2); |
| //determine the output |
| } |
| <script type="text/javascript"> |
| function CreateChart1() |
| { |
| PageMethods.GetChart1(Chart1Render, OnFailure); |
| } |
| function Chart1Render(res) |
| { |
| $get("chart1").innerHTML = res; |
| } |
| function OnFailure(res) |
| { |
| alert(res); |
| } |
| </script> |