you can do like this .....
Note. This is an example of an example of how to print mschart in an asp.net web application, you can change this depending on your requirements .......
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.UI.DataVisualization.Charting;
using System.IO;
using System.Web.UI.WebControls;
namespace Avatar_Reports
{
public class ExtendedChart : Chart
{
public string SerializedString { get; set; }
public void UpdateSerializedString()
{
using (MemoryStream writer = new MemoryStream())
{
this.Serializer.Content = SerializationContents.All;
this.Serializer.Save(writer);
this.SerializedString = GetStringFromStream(writer);
}
}
public ExtendedChart GetChartFromSerialized()
{
ExtendedChart clonedChart = new ExtendedChart();
byte[] chartAsArray = System.Text.Encoding.Default.GetBytes(this.SerializedString);
using (MemoryStream reader = new MemoryStream(chartAsArray))
{
clonedChart.Serializer.Content = SerializationContents.All;
clonedChart.Serializer.Load(reader);
}
return clonedChart;
}
private string GetStringFromStream(Stream stream)
{
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
then you create a page with a kind of object like this:
.....
ExtendedChart ReportChart = new ExtendedChart();
Series Series1 = new Series("Series1");
ChartArea ChartArea1 = new ChartArea("ChartArea1");
....... and then you can use a method call like this in your menu
SerializeChartControls(outputTable);
Session["CtrlToPrint"] = outputTable;
Page.ClientScript.RegisterStartupScript(this.GetType(),
"Print", "<script language='javascript'>window.open('Print.aspx','PrintMe','height=1000px,width=900px,scrollbars=1');</script>");
......
private void SerializeChartControls(Control root)
{
foreach (Control c in root.Controls)
{
if (c is Chart)
{
ExtendedChart theChart = c as ExtendedChart;
theChart.UpdateSerializedString();
}
else if ((c != null) && (c.HasControls() == true))
{
SerializeChartControls(c);
}
}
}
And you PRINT.ASPX could be like this:
.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.UI.DataVisualization.Charting;
namespace Avatar_Reports
{
public partial class Print : System.Web.UI.Page
{
private WebControl ctrlToPrint;
private string footerText = String.Empty;
protected void Page_PreInit(object sender, EventArgs e)
{
if (!IsPostBack)
{
ctrlToPrint = (WebControl)Session["CtrlToPrint"];
DeserializeChartControls(ctrlToPrint);
ExpandAllGridViews(ctrlToPrint);
}
}
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
Panel titlePanel = new Panel();
Label reportTitle = new Label();
titlePanel.CssClass = "ReportTitlePrinted";
ctrlToPrint.Style.Add("text-align", "center");
Page.Form.Controls.Add(ctrlToPrint);
}
}
protected void Page_Load(object sender, EventArgs e)
{
this.RegisterStartupScript("printPopup", "<script>window.print();</script>");
}
private void DeserializeChartControls(Control root)
{
foreach (Control c in root.Controls)
{
if (c is ExtendedChart)
{
ExtendedChart theChart = c as ExtendedChart;
ExtendedChart newChart = theChart.GetChartFromSerialized();
WebControl chartParent = theChart.Parent as WebControl;
int chartIndex = chartParent.Controls.IndexOf(theChart);
chartParent.Controls.AddAt(chartIndex, newChart);
chartParent.Controls.Remove(theChart);
}
else if ((c != null) && (c.HasControls() == true))
{
DeserializeChartControls(c);
}
}
}
Hope this helps you ....