Printing problems with Polar series (bug with CustomRadius)

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
lars
Newbie
Newbie
Posts: 7
Joined: Tue Jul 08, 2003 4:00 am
Location: Sweden

Printing problems with Polar series (bug with CustomRadius)

Post by lars » Thu Jan 05, 2006 11:27 am

When printing a Polar series at a predefined size using the polar.Printer.Print(rect) call the size of the polar chart will be sized to the wanted size regardless of the size on screen. Fine!
But this doesn't work when the CustomXRadius and CustomYRadius are used.

In our application we are adding some stuff outside the polar circle using the BeforeDraw and AfterDraw events. Therefore we have to use a smaller size for the polar circle. We therefore calculates the size of the circle on the SizeChanged event by setting the CustomX/YRadius.

Please try the demo below. Try the Print at different sizes of the window. Outprint is ok when not using Custom radius.

It obviously seems to be a bug here. The version tested are 1.1.2179 and 2.0.2040.
I have tried to find a work-around but I haven't found any that is acceptable. I can't see any way to trap the internal resizing that the Printer.Print(rect) is performing.

Any suggestions for a work-around???

Thanks in advance!

//Lars Jönson, Sweden

Demo code here:

Code: Select all

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace PolarPrintDemo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
    private Steema.TeeChart.TChart tChart1;
    private Steema.TeeChart.Styles.Polar polar1;
    private System.Windows.Forms.Button printButton;
    private System.Windows.Forms.Button exitButton;
    private System.Windows.Forms.CheckBox customCheckBox;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
      myInit();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.tChart1 = new Steema.TeeChart.TChart();
      this.polar1 = new Steema.TeeChart.Styles.Polar();
      this.printButton = new System.Windows.Forms.Button();
      this.exitButton = new System.Windows.Forms.Button();
      this.customCheckBox = new System.Windows.Forms.CheckBox();
      this.SuspendLayout();
      // 
      // tChart1
      // 
      this.tChart1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      // 
      // tChart1.Aspect
      // 
      this.tChart1.Aspect.Elevation = 315;
      this.tChart1.Aspect.Orthogonal = false;
      this.tChart1.Aspect.Perspective = 0;
      this.tChart1.Aspect.Rotation = 360;
      this.tChart1.Aspect.View3D = false;
      this.tChart1.BackColor = System.Drawing.Color.White;
      // 
      // tChart1.Header
      // 
      this.tChart1.Header.Lines = new string[] {
                                                 "TeeChart"};
      this.tChart1.Location = new System.Drawing.Point(0, 0);
      this.tChart1.Name = "tChart1";
      // 
      // tChart1.Panel
      // 
      // 
      // tChart1.Panel.Brush
      // 
      this.tChart1.Panel.Brush.Color = System.Drawing.Color.White;
      this.tChart1.Series.Add(this.polar1);
      this.tChart1.Size = new System.Drawing.Size(760, 416);
      this.tChart1.TabIndex = 0;
      this.tChart1.SizeChanged += new System.EventHandler(this.tChart1_SizeChanged);
      this.tChart1.ChartPrint += new Steema.TeeChart.ChartPrintEventHandler(this.tChart1_ChartPrint);
      // 
      // polar1
      // 
      // 
      // polar1.Brush
      // 
      this.polar1.Brush.Color = System.Drawing.Color.Red;
      this.polar1.Circled = true;
      // 
      // polar1.Pen
      // 
      this.polar1.Pen.Color = System.Drawing.Color.Red;
      // 
      // polar1.Pointer
      // 
      // 
      // polar1.Pointer.Brush
      // 
      this.polar1.Pointer.Brush.Color = System.Drawing.Color.FromArgb(((System.Byte)(254)), ((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)));
      this.polar1.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle;
      this.polar1.ShowInLegend = false;
      this.polar1.Title = "polar1";
      // 
      // polar1.XValues
      // 
      this.polar1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
      // 
      // printButton
      // 
      this.printButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
      this.printButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.printButton.Location = new System.Drawing.Point(8, 432);
      this.printButton.Name = "printButton";
      this.printButton.TabIndex = 1;
      this.printButton.Text = "Print";
      this.printButton.Click += new System.EventHandler(this.printButton_Click);
      // 
      // exitButton
      // 
      this.exitButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
      this.exitButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.exitButton.Location = new System.Drawing.Point(680, 432);
      this.exitButton.Name = "exitButton";
      this.exitButton.TabIndex = 2;
      this.exitButton.Text = "Exit";
      this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
      // 
      // customCheckBox
      // 
      this.customCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
      this.customCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.customCheckBox.Location = new System.Drawing.Point(208, 432);
      this.customCheckBox.Name = "customCheckBox";
      this.customCheckBox.Size = new System.Drawing.Size(104, 16);
      this.customCheckBox.TabIndex = 3;
      this.customCheckBox.Text = "Custom radius";
      this.customCheckBox.CheckedChanged += new System.EventHandler(this.customCheckBox_CheckedChanged);
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(760, 462);
      this.Controls.Add(this.customCheckBox);
      this.Controls.Add(this.exitButton);
      this.Controls.Add(this.printButton);
      this.Controls.Add(this.tChart1);
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);

    }
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		
    private Rectangle frameRect;

    private void myInit()
    {
      frameRect = new Rectangle(10, 30, 1072, 700);
      polar1.FillSampleValues(25);
    }

    [STAThread]
		static void Main() 
		{
      Application.EnableVisualStyles();
			Application.Run(new Form1());
		}
    private void customCheckBox_CheckedChanged(object sender, System.EventArgs e)
    {
      calcCustomSize();
    }
    private void printButton_Click(object sender, System.EventArgs e)
    {
      tChart1.Printer.Landscape = true;
      tChart1.Printer.BeginPrint();
      tChart1.Printer.Print(frameRect);
      tChart1.Printer.Preview();
    }
    private void exitButton_Click(object sender, System.EventArgs e)
    {
      Application.Exit();
    }
    private void tChart1_SizeChanged(object sender, System.EventArgs e)
    {
      calcCustomSize();
    }
    private void tChart1_ChartPrint(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
      // some custom printing
      e.Graphics.DrawRectangle(new Pen(Color.Black), frameRect);
    }
    private void calcCustomSize()
    {
      if (customCheckBox.Checked)
      {
        // do some silly custom calculation of size
        int x, y, rad;
        x = tChart1.Width / 2 - 70;
        y = tChart1.Height / 2 - 70;
        rad = Math.Min(x, y);
        polar1.CustomXRadius = rad;
        polar1.CustomYRadius = rad;
      }
      else
      {
        polar1.CustomXRadius = 0;
        polar1.CustomYRadius = 0;
      }
    }
	}
}

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Jan 09, 2006 3:27 pm

Hello,
When printing a Polar series at a predefined size using the polar.Printer.Print(rect) call the size of the polar chart will be sized to the wanted size regardless of the size on screen. Fine!
But this doesn't work when the CustomXRadius and CustomYRadius are used.
I'm not sure that what you say above is correct. Try changing frameRect to:

Code: Select all

frameRect = new Rectangle(10, 10, 500, 600);
Printing out two charts, one with custom radius and one without, gives you charts which are correctly printed to their relative proportions. Please note that in both printouts the teechart header ("TeeChart") is in exactly the same position, confirming the fact that both charts are respecting the specified rectangle.
Any suggestions for a work-around???
May I suggest that you work either with the resulting print document E.g.

Code: Select all

	tChart1.Printer.Landscape = true;
			tChart1.Printer.BeginPrint();
			tChart1.Printer.Print(frameRect);
			System.Drawing.Printing.PrintDocument pdoc = tChart1.Printer.PrintDocument;
or that you export your chart to a Metafile and do the scaling there.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

lars
Newbie
Newbie
Posts: 7
Joined: Tue Jul 08, 2003 4:00 am
Location: Sweden

Post by lars » Wed Jan 11, 2006 9:25 am

Hi, thanks for your answer!

But I don't agree with you that the scaling works! Run my demo and maximize the window, without custom radius the outprint is ok but with custom radius the outprint will be clipped.

The problem is the hidden scaling that is performed when the print is called. Why is there no scaling event to catch during this? Are there no events fired during the rescaling?

Work arounds:
1. using PrintDocument seems no good for us
2. Metafile. Can you please show me how to do?

Best regards
Lars Jönson

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jan 11, 2006 11:29 am

Hi Lars,

We've been able to reproduce the problem you reported maximizing the window. It is a defect and I've already added it to our bug list (TF02011165) to be fixed for future releases.

In the meantime, you can create you our PrintDocument using a metafile as Printing uses the Graphics of the System.Drawing.Printing.PrintPageEventArgs thus:

Code: Select all

e.Graphics.DrawImage(m /*metafile from Steema.TeeChart.TChart.Metafile*/,r /*rectangle to draw to*/ ,chart.chartBounds,GraphicsUnit.Pixel); 
Best Regards,
Narcís Calvet / 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