Hello, I'm working on a wcf service and trying to create a chart serverside and save it as image so that I can send the image url to external users. Here is the complete code:
var chart = new System.Web.UI.DataVisualization.Charting.Chart(); chart.EnableViewState = false; chart.Titles.Add(new System.Web.UI.DataVisualization.Charting.Title()); chart.Titles[0].Text = "Cash Balance Comparison"; chart.Titles[0].Alignment = System.Drawing.ContentAlignment.TopCenter; chart.Visible = true; chart.Legends.Add("Legend1"); var series = chart.Series.Add("School 1"); series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeColumn; series.Points.AddXY("dept 1", 12345); series.Points.AddXY("dept 2", 345); series.Points.AddXY("dept 3", 345); series.Points.AddXY("dept 4", 5656); series = chart.Series.Add("School 2"); series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeColumn; series.Points.AddXY("dept 1", 54345); series.Points.AddXY("dept 2", 444); series.Points.AddXY("dept 3", 54345); series.Points.AddXY("dept 4", 9090); series = chart.Series.Add("School 3"); series.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeColumn; series.Points.AddXY("dept 1", 239); series.Points.AddXY("dept 2", 2397); series.Points.AddXY("dept 3", 23237); series.Points.AddXY("dept 4", 2234487); chart.Legends[0].Docking = System.Web.UI.DataVisualization.Charting.Docking.Bottom; chart.Legends[0].TitleAlignment = System.Drawing.StringAlignment.Center; chart.Legends[0].Alignment = System.Drawing.StringAlignment.Center; chart.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.ImageTag; string path = @"C:\temp\Charts\test.png"; chart.ImageLocation = path; chart.SaveImage(path, System.Web.UI.DataVisualization.Charting.ChartImageFormat.Png); chart.Dispose(); chart = null; return path;
It saves an image with a chart title, but doesn't contain anything else. Can someone please let me know why its not working?
Any help will be highly appreciated.
Thanks.