Axes Labels

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
SPS
Newbie
Newbie
Posts: 18
Joined: Wed Jun 29, 2005 4:00 am

Axes Labels

Post by SPS » Tue Jun 23, 2009 11:15 am

Hi,

I'm trying to make a bar chart with text labels on the left axis. But when i resize the window the label font size is not adjusted. Is there a solution for this problem?

Here is some sample code i'm using:

InitializeComponent();
chartController1.Chart = tChart1;
tChart1.Aspect.View3D = false;
this.tChart1.Chart.Legend.Visible = false;
this.tChart1.Chart.Axes.Bottom.Visible = false;

horizBar1 = new Steema.TeeChart.Styles.HorizBar(this.tChart1.Chart);
horizBar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Percent;
tChart1.Axes.Left.Labels.Align = Steema.TeeChart.AxisLabelAlign.Opposite;

horizBar1.Add(150, "bar label 1",Color.Red);
horizBar1.Add(120, "bar label 2", Color.Black);
horizBar1.Add(100, "bar label 3", Color.Blue);
horizBar1.Marks.Visible = false;

this.tChart1.Chart.Axes.Left.Labels.AutoSize = true;
horizBar1.YValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
this.tChart1.Walls.Visible = false;
this.tChart1.Chart.Series.Add(horizBar1);

When resizing the window the label text size is not changed. I would like to have the font size of the labels smaller when the window size gets smaller.

I also tried it with: (tChart1.Axes.Left.Labels.Items.Add(2, "bar label 1")).Font.Size = 16;
But then i need to recalculate the font size manually in the SizeChanged event?

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

Re: Axes Labels

Post by Yeray » Tue Jun 23, 2009 2:41 pm

Hi SPS,

Try using OnResize event as follows. The following code assigns the event:

Code: Select all

this.tChart1.Resize += new EventHandler(tChart1_Resize);
And this calculates the left axis labels font size proportionally to the left axis size:

Code: Select all

        void tChart1_Resize(object sender, EventArgs e)
        {
            this.tChart1.Draw();
            this.tChart1.Axes.Left.Labels.Font.Size = ((this.tChart1.Axes.Left.IEndPos - this.tChart1.Axes.Left.IStartPos) / (horizBar1.Count * 10));
        }
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

SPS
Newbie
Newbie
Posts: 27
Joined: Tue May 26, 2009 12:00 am

Re: Axes Labels

Post by SPS » Thu Jul 09, 2009 1:17 pm

This formula doesnt seem to work correct, when i only change the height of the window the font size gets bigger until the mark text doesnt fit in the window anymore. What exactly is IEndPos and IStartPos ?

Also when i have set the property: horizBar1.Marks.Transparent = true;
And then in the resize event method i do something like: int a = horizBar1.Marks.Items.Font.Size; the transparant seems to be gone since i see the mark
rectangle again.

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

Re: Axes Labels

Post by Yeray » Thu Jul 09, 2009 2:01 pm

Hi SPS,

I suppose that our projects have different responses because we have different Dock styles for our charts, or maybe there is another property I'm missing to set. So, could you please attach a simple example project we can run as-is to reproduce the problem here?

IStartPos and IEndPos are the number of pixels from the top (top if we are talking about vertical axes, left if we are talking about horizontal axes) of the chart to the Start or the End position of the axis. You can play with those values through the chartcontroller (Chart/Axes/Position tab) to see the effect of changing their values.
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

SPS
Newbie
Newbie
Posts: 27
Joined: Tue May 26, 2009 12:00 am

Re: Axes Labels

Post by SPS » Thu Jul 09, 2009 2:20 pm

I have attached a simple horbar test project
Attachments
HorBarTest.zip
HorBar chart test with resize labels, resizing doesn't work good
(11.35 KiB) Downloaded 556 times

SPS
Newbie
Newbie
Posts: 27
Joined: Tue May 26, 2009 12:00 am

Re: Axes Labels

Post by SPS » Thu Jul 09, 2009 3:02 pm

I have solved the problem by setting a max font size, but it would be nice to have an option in teechart that automatic calculates the label sizes and mark label sizes based on the window screen width/height.

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

Re: Axes Labels

Post by Yeray » Thu Jul 09, 2009 3:28 pm

Hi SPS,

We'll consider to add a new property to make this automatically. In the meanwhile, the following code seems to work better in your application and doesn't loop into your series:

Code: Select all

void tChart1_Resize(object sender, EventArgs e)
{
    tChart1.Draw(this.CreateGraphics());
    horizBar1.Marks.Transparent = true;
    this.tChart1.Axes.Left.Labels.Font.Size = ((this.tChart1.Axes.Left.IEndPos - this.tChart1.Axes.Left.IStartPos) / (horizBar1.Count * 5));
    horizBar1.Marks.Font.Size = ((this.tChart1.Axes.Left.IEndPos - this.tChart1.Axes.Left.IStartPos) / (horizBar1.Count * 5));
}
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

Post Reply