Print multiple charts in either single or multiple pages

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Beige
Newbie
Newbie
Posts: 25
Joined: Wed Jun 28, 2006 12:00 am

Print multiple charts in either single or multiple pages

Post by Beige » Thu Feb 18, 2010 12:06 pm

I am using TeeChart in my asp.net application. I am new to TeeChart and facing an issue as below.

I want to print multiple charts either in single page or in multiple pages. Decision should be taken from print preview window taking care of selected paper size, orientation etc. I have tried by sending multiple charts to print preview. But if I select smaller paper size or zoom up the chart, there is a cut off. It always prints a single page. How do I ensure if all charts are not fit to single page but rather should be printed on multiple pages.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Print multiple charts in either single or multiple pages

Post by Yeray » Thu Feb 18, 2010 2:20 pm

Hi Beige,

I think you should do something similar as what Narcís suggested here
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Beige
Newbie
Newbie
Posts: 25
Joined: Wed Jun 28, 2006 12:00 am

Re: Print multiple charts in either single or multiple pages

Post by Beige » Fri Feb 19, 2010 9:59 am

thanks for reply. Good suggestion by Narcís. but it does not suggest any print preview. And one more point, how do I draw multiple chart in a single PrintPageEventArgs? Again System.Drawing.Printing.PrintDocument document.print(), prints whole document in a single page. How to print multiple page?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Print multiple charts in either single or multiple pages

Post by Yeray » Fri Feb 19, 2010 3:34 pm

Hi Biege,

Take a look at this example. I think it should be a good start point to achieve what you are trying to do:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
        private System.Drawing.Printing.PrintDocument printDocument1 = new System.Drawing.Printing.PrintDocument();
        private Steema.TeeChart.TChart[] Charts;

        private void InitializeChart()
        {
            Charts = new Steema.TeeChart.TChart[5];

            for (int i = 0; i < Charts.Length; i++)
            {
                Charts[i] = new Steema.TeeChart.TChart();
                Charts[i].Parent = this;
                Charts[i].Top = 100;
                Charts[i].Left = i*Charts[0].Width;

                switch (i)
                {
                    case 0: new Steema.TeeChart.Styles.Line(Charts[i].Chart);                        
                        break;

                    case 1: new Steema.TeeChart.Styles.Bar(Charts[i].Chart);
                        break;

                    case 2: new Steema.TeeChart.Styles.Pie(Charts[i].Chart);
                        break;
                    default: new Steema.TeeChart.Styles.Points(Charts[i].Chart);
                        break;
                }

                Charts[i][0].FillSampleValues();
            }
            
            printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
        }

        private void button1_Click(object sender, EventArgs e)
        {                        
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();            
        }

        void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Rectangle r;
            System.Drawing.Imaging.Metafile m;

            for (int i = 0; i < Charts.Length; i++)
            {
                r = new Rectangle(10, 10 + i*200, 700, 200);
                m = Charts[i].Chart.Metafile(Charts[i].Chart, r.Width, r.Height);
                e.Graphics.DrawImage(m, r, Charts[i].Chart.ChartBounds, GraphicsUnit.Pixel);
            }            
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Beige
Newbie
Newbie
Posts: 25
Joined: Wed Jun 28, 2006 12:00 am

Re: Print multiple charts in either single or multiple pages

Post by Beige » Mon Feb 22, 2010 2:32 pm

Yes Biege, this works ok for windows form application. I need similar functionality for my asp.net web application. Is it possible to show windows forms in asp.net?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Print multiple charts in either single or multiple pages

Post by Sandra » Tue Feb 23, 2010 1:06 pm

Hello Beige,

I made a simple example using last of TeeChart.Net (version 4) and similar code of Yeray’s posted in previously. Please check next code works as you want.

Code: Select all

    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeChart();
    }
    private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
    private System.Drawing.Printing.PrintDocument printDocument1 = new System.Drawing.Printing.PrintDocument();
    private void InitializeChart()
    {
        Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(WebChart1.Chart);
        Steema.TeeChart.Styles.Bar  bar1= new Steema.TeeChart.Styles.Bar(WebChart2.Chart);
        Steema.TeeChart.Styles.Pie  pie1 = new Steema.TeeChart.Styles.Pie(WebChart3.Chart);
        Steema.TeeChart.Styles.Points  points1 = new Steema.TeeChart.Styles.Points(WebChart4.Chart);
        line1.FillSampleValues();
        bar1.FillSampleValues();
        pie1.FillSampleValues();
        points1.FillSampleValues();
        printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
    }

    void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        System.Drawing.Rectangle r1,r2,r3,r4;
        System.Drawing.Imaging.Metafile m1,m2,m3,m4;
        //WebChart1
        r1 = new System.Drawing.Rectangle(10, 10 + 1 * 200, 700, 200);
        m1 = WebChart3.Chart.Metafile(WebChart1.Chart, r1.Width, r1.Height);
        e.Graphics.DrawImage(m1, r1, WebChart1.Chart.Chart.ChartBounds, System.Drawing.GraphicsUnit.Pixel);
        //WebChart2
        r2 = new System.Drawing.Rectangle(10, 10 + 2 * 200, 700, 200);
        m2 = WebChart2.Chart.Metafile(WebChart2.Chart, r2.Width, r2.Height);
        e.Graphics.DrawImage(m2, r2, WebChart2.Chart.Chart.ChartBounds, System.Drawing.GraphicsUnit.Pixel);
        //WebChart3
        r3 = new System.Drawing.Rectangle(10, 10 + 3* 200, 700, 200);
        m3 = WebChart3.Chart.Metafile(WebChart3.Chart, r3.Width, r3.Height);
        e.Graphics.DrawImage(m3, r3, WebChart3.Chart.Chart.ChartBounds, System.Drawing.GraphicsUnit.Pixel);
        //WebChart4
        r4= new System.Drawing.Rectangle(10, 10 + 4 * 200, 700, 200);
        m4 = WebChart3.Chart.Metafile(WebChart4.Chart, r4.Width, r4.Height);
        e.Graphics.DrawImage(m4, r4, WebChart4.Chart.Chart.ChartBounds, System.Drawing.GraphicsUnit.Pixel);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.ShowDialog();
    }
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply