How to draw title of left axis vertically

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Schatz_AG
Newbie
Newbie
Posts: 5
Joined: Mon Mar 25, 2013 12:00 am

How to draw title of left axis vertically

Post by Schatz_AG » Mon Apr 22, 2013 2:35 pm

Hallo,

we use TeeChart for C# in an Windows CE 7.0 environment (.NET Compact Framework 3.5).

I want to display the title of the left axis vertically:

Code: Select all

    Chart1.Axes.Left.MinorTickCount = 4;
    Chart1.Axes.Left.Title.Text = "Md [N.m]";
    Chart1.Axes.Left.Title.Angle = 90;
Nevertheless the axis title is displayed horizontally.
What can I do ?

Thanks in advance

Lothar Weidl-Walther

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

Re: How to draw title of left axis vertically

Post by Sandra » Tue Apr 23, 2013 10:47 am

Hello Lothar Weidl-Walther,

Thanks for your information. The axislabel.angle and axisTitle.angle properties were designed using the System.Drawing.Drawing2D.Matrix class to perform the point transformation. As this class does not exist in the .net CF then a feature request has already been added to the wishlist with number [TC26010085] try an enable a similar functionality in this environment.

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

Schatz_AG
Newbie
Newbie
Posts: 5
Joined: Mon Mar 25, 2013 12:00 am

Re: How to draw title of left axis vertically

Post by Schatz_AG » Tue May 07, 2013 3:21 pm

Hello,

I still try to find a method to draw a vertical text in my TeeChart. (TeeChart for C# in an Windows CE 7.0 environment (.NET Compact Framework 3.5).
I tried the AfterDraw event of TChart according to Tutorial13 of TeeChart Pro .Net Tutorial:

Code: Select all

  Chart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(Chart1_AfterDraw);

  protected void Chart1_AfterDraw(object sender, Graphics3D g)
  {
    Graphics myGraphic = Chart1.CreateGraphics();
    Font myFont = CreateRotatedFont("Arial", 12, 90, myGraphic);

    Brush myBrush = new SolidBrush(Color.Red);
    RectangleF myRect = new RectangleF(20, 150, 50, -100);

    myGraphic.DrawString("Hello", myFont, myBrush, myRect);
    myGraphic.Dispose();  myFont.Dispose();  myBrush.Dispose();
  }

  public static Font CreateRotatedFont(string fontname, int height, int angleInDegrees, Graphics g1)
  {
    LogFont logf = new LogFont();
    logf.Height = -1 * height;
    logf.FaceName = fontname;
    logf.Escapement = angleInDegrees * 10;
    logf.Orientation = logf.Escapement;
    logf.CharSet = LogFontCharSet.Default;
    logf.OutPrecision = LogFontPrecision.Default;
    logf.ClipPrecision = LogFontClipPrecision.Default;
    logf.Quality = LogFontQuality.ClearType;
    logf.PitchAndFamily = LogFontPitchAndFamily.Default;
    return Font.FromLogFont(logf);
  }
When I use a breakpoint inside Chart1_AfterDraw, I can see the vertical text, but afterwards it is overridden by the TeeChart panel. For me it seens, as if the event is fired "BeforeDraw" ?

Is there another way ?

with kind regards
Lothar Weidl-Walther

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

Re: How to draw title of left axis vertically

Post by Sandra » Wed May 08, 2013 10:10 am

Hello Lothar Weidl-Walther,

Thanks for your code,but I can not reproduce your problem with it. I would be very grateful if you can send us your complete example, because we can reproduce you code exactly?

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

Schatz_AG
Newbie
Newbie
Posts: 5
Joined: Mon Mar 25, 2013 12:00 am

Re: How to draw title of left axis vertically

Post by Schatz_AG » Wed May 15, 2013 2:18 pm

Hello Sandra Pazos,

thank you for your answer; when restricting my problem to a small sample project I found my fault:

Instead "Chart1.CreateGraphics()" "g.GDIplusCanvas" has to be used as graphics/canvas for drawing the vertical text!

I am very glad to have not the best, but a useful solution, completely:

Code: Select all

  (... constructing Chart1...)
  Chart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(Chart1_AfterDraw);

  protected void Chart1_AfterDraw(object sender, Graphics3D g)
  {
    Font myFont = CreateRotatedFont("Arial", 12, 90);
    Brush myBrush = new SolidBrush(Color.Red);
    RectangleF myRect = new RectangleF(8, 150, 300, -100);

    g.GDIplusCanvas.DrawString("Hello", myFont, myBrush, myRect);
    myFont.Dispose();
    myBrush.Dispose();
  }

  public static Font CreateRotatedFont(string fontname, int height, int angleInDegrees)
  {
    LogFont logf = new LogFont();
    logf.Height = -1 * height;
    logf.FaceName = fontname;
    logf.Escapement = angleInDegrees * 10;
    logf.Orientation = logf.Escapement;
    logf.CharSet = LogFontCharSet.Default;
    logf.OutPrecision = LogFontPrecision.Default;
    logf.ClipPrecision = LogFontClipPrecision.Default;
    logf.Quality = LogFontQuality.ClearType;
    logf.PitchAndFamily = LogFontPitchAndFamily.Default;
    return Font.FromLogFont(logf);
  }
Best regards
Lothar Weidl-Walther

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

Re: How to draw title of left axis vertically

Post by Sandra » Thu May 16, 2013 9:23 am

Hello Lothar Weidl-Walther,

Thanks for your code. I have tried to use the code, but I need the class LogFont to achieve uses code here, for this reason, I have made a new code. Using my code in latest version of TeeChartFor.Net, published in January 2013, I can't reproduce your problem:

Code: Select all

     private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            Steema.TeeChart.Styles.Points points = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            points.FillSampleValues(5);
            tChart1.Draw();
            tChart1.AfterDraw  = tChart1_AfterDraw;
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {

            Font myFont = new Font("Arial", 12, FontStyle.Bold);
            Brush myBrush = new SolidBrush(Color.Red);
            g.Brush.Color = Color.Red;
            Rectangle myRect = new Rectangle(100, 150, 13, 100);
            g.GDIplusCanvas.DrawString("Hello", myFont, myBrush, myRect);
            myFont.Dispose();
            myBrush.Dispose();
        }
Could you tell us if using my code you can work in correct way? On the other hand, If your problem persist and my code doesn't help you to solve your problem, I would be very grateful,if you send us the LogFont class, because we can try to find a solution for you.

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

Schatz_AG
Newbie
Newbie
Posts: 5
Joined: Mon Mar 25, 2013 12:00 am

Re: How to draw title of left axis vertically

Post by Schatz_AG » Tue May 21, 2013 9:41 am

Hello Sandra Pazos,

the LogFont class is a part of Windows CE 7.0 (.NET Compact Framework 3.5) (please see code).

Code: Select all

[b]Form1.cs:[/b]
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
using Steema.TeeChart.Pocket;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Drawing;

namespace AfterDraw
{
  public partial class Form1 : Form
 {
    private TChart Chart1;
    private FastLine Graph;
    string LeftAxisTitle;

    public Form1()
    {
      InitializeComponent();

      Chart1 = new TChart();
      Chart1.Aspect.View3D = false;
      Chart1.Legend.Visible = false;
      Chart1.Chart.Panel.MarginLeft = 5;  // give place for the title

      Chart1.Axes.Bottom.MinorTickCount = 4;
      Chart1.Axes.Bottom.Automatic = false;
      Chart1.Axes.Bottom.SetMinMax(0, 3);
      Chart1.Axes.Bottom.Labels.Separation = 40;
      Chart1.Axes.Bottom.Title.Text = "Time [s]";
      Chart1.Axes.Left.Automatic = false;
      Chart1.Axes.Left.SetMinMax(0, 10);
      LeftAxisTitle = "Torque [N.m]";

      Graph = new FastLine(Chart1.Chart);
      Chart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(Chart1_AfterDraw);

      // inserting the Chart into the form
      Chart1.Size = new Size(500, 300);
      Chart1.Location = new Point(100, 20);
      this.Controls.Add(Chart1);
    }

    protected void Chart1_AfterDraw(object sender, Graphics3D g)
    {
      float CharWidth;  // average width of a char
      int StrWidth;     // length of the in pixel
      int StartPos;     // y value of the start position for writing (0 = top position)

      Font myFont = CreateRotatedFont("Tahoma", 11, 90);
      Brush myBrush = new SolidBrush(Color.Black);
      // calculation of centered placement; 
      // Microsoft.WindowsMobile.DirectX.Direct3D.Font.MeasureString seems in my eyes to be too much overhead for a smart device
      CharWidth = 0.75F * myFont.Size;
      StrWidth = Convert.ToInt32(LeftAxisTitle.Length * CharWidth);
      StartPos = (Chart1.Height - 10 + StrWidth) / 2;  // 10: including title of X axes
      RectangleF myRect = new RectangleF(8, StartPos, 300, -100);  // 3rd number: length of the print area, not understood (??)

      g.GDIplusCanvas.DrawString(LeftAxisTitle, myFont, myBrush, myRect);
      myFont.Dispose();
      myBrush.Dispose();
    }

    public static Font CreateRotatedFont(string fontname, int height, int angleInDegrees)
    {
      Microsoft.WindowsCE.Forms.LogFont logf = new LogFont();
      logf.Height = -1 * height;
      logf.FaceName = fontname;
      logf.Escapement = angleInDegrees * 10;
      logf.Orientation = logf.Escapement;
      logf.CharSet = LogFontCharSet.Default;
      logf.OutPrecision = LogFontPrecision.Default;
      logf.ClipPrecision = LogFontClipPrecision.Default;
      logf.Quality = LogFontQuality.ClearType;
      logf.PitchAndFamily = LogFontPitchAndFamily.Default;
      return Font.FromLogFont(logf);
    }
  }
}

[b]Form1.Designer.cs:[/b]
namespace AfterDraw
{
  partial class Form1
  {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;
    private System.Windows.Forms.MainMenu mainMenu1;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
      if (disposing && (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.mainMenu1 = new System.Windows.Forms.MainMenu();
      this.SuspendLayout();
      // Form1
      this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
      this.AutoScroll = true;
      this.ClientSize = new System.Drawing.Size(625, 360);
      this.Location = new System.Drawing.Point(0, 20);
      this.Menu = this.mainMenu1;
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);
    }
    #endregion
  }
}
The last 2 parameters for the RectangleF function I found by "try and error".
The form Form1 is a clear form. The chart is filled in the constructor of Form1, because in my Visual Studio TeeChart is not integrated in the toolbox.

With best regards
Lothar Weidl-Walther

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

Re: How to draw title of left axis vertically

Post by Sandra » Wed May 22, 2013 2:33 pm

Hello Lothar Weidl-Walthe,

I have work with your problem and we will try to answer you asap.

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

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

Re: How to draw title of left axis vertically

Post by Sandra » Wed May 29, 2013 11:01 am

Hello Lothar Weidl-Walthe,

Sorry for the delay, but I have had many problems in my computer to execute the program because works using LogFont class, but, finally I have achieved it. First, I apologize, so I understood you had some problems in your code, I made a mistake, sorry for the confusion. In the other hand, I consider your project is a good solution but I think you must use general values to treat the position of text, for this reason, I have modified your code because it works in a optimize way for all versions of Windows CE. Moreover I think this code can help other client have a similar problem as you.
References needed:

Code: Select all

using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Pocket;
using Microsoft.WindowsCE.Forms;
Code:

Code: Select all

        private TChart Chart1;
        private FastLine Graph;
        string LeftAxisTitle;
        public Form1()
        {
            InitializeComponent();
            //InitializeChart
            Chart1 = new TChart();
            this.Controls.Add(Chart1); 
            Chart1.Size = new Size(500, 300);
            Chart1.Location = new Point(100, 20);
            Chart1.Aspect.View3D = false;
            Chart1.Legend.Visible = false;
            Chart1.Chart.Panel.MarginLeft = 5;  // give place for the title
            //Add a Series
            Graph = new FastLine(Chart1.Chart);
            Graph.FillSampleValues(10); 
            //Customize axes values. 
            Chart1.Axes.Bottom.MinorTickCount = 4;
            Chart1.Axes.Bottom.Automatic = false;
            Chart1.Axes.Bottom.SetMinMax(0, 3);
            Chart1.Axes.Bottom.Labels.Separation = 40;
            Chart1.Axes.Bottom.Title.Text = "Time [s]";            
            LeftAxisTitle = "Torque [N.m]";
            Chart1.Axes.Left.Automatic = false;
            Chart1.Axes.Left.SetMinMax(0, Graph.YValues.Maximum);
            Chart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(Chart1_AfterDraw);
            Chart1.Invalidate();
        }
        protected void Chart1_AfterDraw(object sender, Graphics3D g)
        {
            int StrWidth;     // length of the in pixel
            int StartPos;     // y value of the start position for writing (0 = top position)
            Font myFont = CreateRotatedFont("Tahoma", 11, 90);
            Brush myBrush = new SolidBrush(Color.Black);
            //Use a general values.
            StrWidth = Convert.ToInt32(LeftAxisTitle.Length * myFont.Size);
            StartPos = (Chart1.Height+StrWidth) / 2; 
            RectangleF myRect = new RectangleF(8, StartPos, StrWidth, -StrWidth);  
            g.GDIplusCanvas.DrawString(LeftAxisTitle, myFont, myBrush, myRect);
            myFont.Dispose();
            myBrush.Dispose();
        }
        public static Font CreateRotatedFont(string fontname, int height, int angleInDegrees)
        {
            Microsoft.WindowsCE.Forms.LogFont logf = new LogFont();
            logf.Height = -1 * height;
            logf.FaceName = fontname;
            logf.Escapement = angleInDegrees * 10;
            logf.Orientation = logf.Escapement;
            logf.CharSet = LogFontCharSet.Default;
            logf.OutPrecision = LogFontPrecision.Default;
            logf.ClipPrecision = LogFontClipPrecision.Default;
            logf.Quality = LogFontQuality.ClearType;
            logf.PitchAndFamily = LogFontPitchAndFamily.Default;
            return Font.FromLogFont(logf);
        }

Many thanks for your code.
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