Left Axis Title and Label separation

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
rperkins
Newbie
Newbie
Posts: 58
Joined: Wed May 26, 2004 4:00 am

Left Axis Title and Label separation

Post by rperkins » Thu Sep 25, 2008 5:46 pm

How do I increase the "gap" between the Left Axis Title and the labels?

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

Post by Narcís » Fri Sep 26, 2008 7:36 am

Hi rperkins,

You should use LabelsSeparation for that:

Code: Select all

  Chart1.Axes.Left.LabelsSeparation:=50; 
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

rperkins
Newbie
Newbie
Posts: 58
Joined: Wed May 26, 2004 4:00 am

Post by rperkins » Fri Sep 26, 2008 1:02 pm

if i change this in the form designer (LeftAxis.LabelSeparation) from 10 to 50, it changes the separation of the horizontal lines (reducing the number of lines).

did i miss something? what i'm looking to do is increase the gap between the axis title (LeftAxis.Title.Caption) - which is turned 90 degrees (up/down), and the labels of the horizontal grid lines, which are numerical values based on the data points.

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

Post by Narcís » Fri Sep 26, 2008 1:22 pm

Hi rperkins,

I'm not sure about which is your exact problem here. Most likely that since the chart area is reduced by incrementing LabelsSeparation, less labels can be fitted in the bottom axis and therefore its increment automatically increases. Is that your problem? If so you'll have to manually set axes Increment manually.
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

rperkins
Newbie
Newbie
Posts: 58
Joined: Wed May 26, 2004 4:00 am

Post by rperkins » Fri Sep 26, 2008 1:39 pm

no, that isn't the problem. what i have is a chart (obviously) with a left axis caption called "Corrected Counts" - which is written at 90 degrees - tilt your head 90 degrees to the left to read. the left axis labels run from -5.00 to 5.00, every 0.5. what is happening is that the bottom of the axis caption is right against the left side of the axis labels. what i'd like to do is to increase/add space between the bottom of the caption and the left side of the axis label.

if you still aren't sure about what i'm asking, i can upload a JPEG of a screen capture. that shows it.

thanks....

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

Post by Narcís » Fri Sep 26, 2008 1:45 pm

Hi rperkins,

Thanks for the information. I think I understand which is your problem and I also think setting LabelsSeparation for left axis labels is the solution but if you have any inconvenient with that please post an image of the original chart, what you get after applying LabelsSeparation and what would you like to get.

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
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

rperkins
Newbie
Newbie
Posts: 58
Joined: Wed May 26, 2004 4:00 am

Post by rperkins » Fri Sep 26, 2008 1:56 pm

uploaded PastedImage_12.jpeg. it shows the before "issue" i'm talking about. look at the left and right sides of the chart - the words "Corrected Counts/Pulse". that's what i'm trying to separate from the value labels.

does that help? i can get the result of setting the LabelSeparation, which doesn't change the distance at the bottom of the axis caption, but, increases the gap between the horizontal grid lines, unless there's another labelsSeparation i'm not setting.

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

Post by Narcís » Fri Sep 26, 2008 2:07 pm

Hi rperkins,

Sorry, my bad! Yes, that's the problem I meant. I confused myself. You don't need to use LabelsSeparation, you need to use LabelsSize :oops:.

For example, this code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 10 do
    Series1.Add(i-5);

  Chart1.Axes.Left.Title.Caption:='My left axis title';
  Chart1.Axes.Right.Title.Caption:='My right axis title';
end;
Produces a chart similar to yours. Increasing LabelsSize solves the problem:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 10 do
    Series1.Add(i-5);

  Chart1.Axes.Left.Title.Caption:='My left axis title';
  Chart1.Axes.Right.Title.Caption:='My right axis title';

  Chart1.Axes.Left.LabelsSize:=30;
  Chart1.Axes.Right.LabelsSize:=30;
end;
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

rperkins
Newbie
Newbie
Posts: 58
Joined: Wed May 26, 2004 4:00 am

Post by rperkins » Fri Sep 26, 2008 2:42 pm

that did it, at least for a static size of less than 30. if the value is large, say 200,000, it is bigger than 30 pixels, so the caption is overwritten by the label. what i need to do is to add something to the add 20-30 to the length of the updated text values - maybe in the AfterDraw handler?

is there a way to get the size of the labels? more specifically, the maximum size of the labels?

where would be a good place to put this "spacer" function?

Oopsnut
Newbie
Newbie
Posts: 4
Joined: Thu Nov 08, 2007 12:00 am

Computing Axis Label Size to space between Axis / Labels

Post by Oopsnut » Sat Sep 27, 2008 3:59 pm

I use the following SetLabelPositions method for Custom Axes. For Left Axis, I think you have to use LabelSize instead of CustomSize. I have found a good place to put this is in a TChart BeforeDraw event handler.

Code: Select all

private void SetLabelPositions()
      {
         SteemaTChart.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
         int width = 0;
         foreach (Steema.TeeChart.Axis axis in SteemaTChart.Axes.Custom)
         {
            try
            {
               width = Math.Max(axis.Labels.LabelWidth(axis.Minimum), width);
               width = Math.Max(axis.Labels.LabelWidth(axis.Maximum), width);
            }
            catch (Exception ex)
            {
               System.Diagnostics.Debug.WriteLine("Failure in SetLabelPositions()");
            }
         }
         width += 5;
         foreach (Steema.TeeChart.Axis axis in SteemaTChart.Axes.Custom)
         {
            axis.Labels.CustomSize = width;
         }
      }
Regards, Ed

Oopsnut
Newbie
Newbie
Posts: 4
Joined: Thu Nov 08, 2007 12:00 am

Computing Axis Label Space

Post by Oopsnut » Sat Sep 27, 2008 4:59 pm

Expanding on my previous post... I am working with the .NET 3 version which seems to have replaced the LabelsSize property with a Labels.CustomSize property. The following code may work for you. However, I can't confirm that your version has a LabelWidth function as the .NET version does.

Code: Select all

private void SetLeftAxisTitleOffset(Steema.TeeChart.TChart lTChart)
      {
         Steema.TeeChart.Axis lAxis = lTChart.Axes.Left;
         int width = lAxis.Labels.LabelWidth(lAxis.Minimum);
         width = Math.Max(lAxis.Labels.LabelWidth(lAxis.Maximum), width);
         width += 5;
         lAxis.LabelsSize = width;
      }
Regards,
Ed

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

Post by Narcís » Mon Sep 29, 2008 7:40 am

Hi rperkins,

Yes, using the OnAfterDraw event would be an option.
is there a way to get the size of the labels? more specifically, the maximum size of the labels?
Yes, you can use Chart1.Axes.Left.MaxLabelsWidth. Bear in mind that this property will only have valid values when the chart has already been painted so running the code in the OnAfterDraw event is a good choice. Another option would be calling Chart1.Draw before.
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

rperkins
Newbie
Newbie
Posts: 58
Joined: Wed May 26, 2004 4:00 am

Post by rperkins » Thu Oct 09, 2008 2:04 pm

based on the information in the previous post, i created a BeforeDrawChart handler (tried in the AfterDraw, but it was 1 refresh behind). the code below results in the appropriate "cushion" between the Axis Title and the Labels. not: in my example, the chart is called crtData.

void __fastcall TfrmChannelOverTime::crtDataBeforeDrawChart(TObject *Sender)
{
int width=0;
width = Max ( crtData->LeftAxis->LabelWidth(crtData->LeftAxis->Minimum), width );
width = Max ( crtData->LeftAxis->LabelWidth(crtData->LeftAxis->Maximum), width );
width += 10;
crtData->LeftAxis->LabelsSize = width;
crtData->RightAxis->LabelsSize = width;
}

Post Reply