Custom Axis Position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Custom Axis Position

Post by Xia » Wed Feb 13, 2008 9:53 am

I added three custom vertical axes in the project and switch between the standard RightAxis and these custom vertical axes. The x position (horizontal position) of the right axis will change automatically according to the length of the right axis label text, but the custom axes always stay in the same x position so sometimes the label text and title are not visible. Which property in the TChartAxis or TChart can be used to set the x position of the Axis to fix or auto change?

Thanks

Xia

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 Feb 13, 2008 1:00 pm

Hi Xia,

It's most likely that you need to set chart's margins as custom axes don't calculate them automatically. For example:

Using percent (default setting):

Code: Select all

    TChart1.Panel.MarginLeft = 5
    TChart1.Panel.MarginRight = 5
Using pixels:

Code: Select all

    TChart1.Panel.MarginUnits = muPixels
    TChart1.Panel.MarginLeft = 50
    TChart1.Panel.MarginRight = 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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Post by Xia » Wed Feb 13, 2008 1:38 pm

Hi Narcis,

Thanks for your email.

I have set the panel MarginRight to 50, but I noticed that the margin for the custom axes is calculated from the vertical axis itself not from the postion of the axis label and title as for the RightAxis. So I have to change the MarginRight when switching from RightAxis to custom axes.

For the RightAxis, is it possible to have the vertical Axis line kept in the same position and not affected by the axis scale or title change? I want to keep the size and position of the ChartRect the same when scrolling the graph vertically .

One more question, I added a vertical TChartScrollBar to scroll custom axes. How to link the scrollbar to one of the custom axes or assosciated data series?

Thanks in advance.

Xia

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 Feb 13, 2008 2:32 pm

Hi Xia,
For the RightAxis, is it possible to have the vertical Axis line kept in the same position and not affected by the axis scale or title change? I want to keep the size and position of the ChartRect the same when scrolling the graph vertically .
You could try one of those 2 options:

1. Use PositionPercent:

Code: Select all

    TChart1.Axis.Right.PositionUnits = puPixels
    TChart1.Axis.Right.PositionPercent = 50
2. Set a margin wider than the axes would need.
One more question, I added a vertical TChartScrollBar to scroll custom axes. How to link the scrollbar to one of the custom axes or assosciated data series?
The easiest way to achieve what you request is using AxisScroll tool.
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Post by Xia » Wed Feb 13, 2008 4:57 pm

Hi Narcis,

Thanks.

I have added TAxisScrollTool to the chart. I can now scroll grpahs for both bottom axis and vertical custom axes. But when I use the axis scroll for the bottom axis, it can scroll to negative values. Because I am using the time for the bottom axis, I don't want to show negative value (time). How can I restrict the horizontal scroll to the minimum of 0 when scrolling the bottom axis? I added codes to Chart->OnScroll event to restrict the bottom axis from 0 and it works when using dragging the right mouse inside the chart space, but dragging the bottom axis did not triger the Chart->OnScroll event.

Also, when scroll the graph, the number of the axis's labels (scales) or the inner ticks varies from 5 to 12. Is it possible to have the fixed number of labels (or inner ticks) for the bottom axis displayed?

Regards

Xia

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

Post by Narcís » Thu Feb 14, 2008 11:11 am

Hi Xia,
I have added TAxisScrollTool to the chart. I can now scroll grpahs for both bottom axis and vertical custom axes. But when I use the axis scroll for the bottom axis, it can scroll to negative values. Because I am using the time for the bottom axis, I don't want to show negative value (time). How can I restrict the horizontal scroll to the minimum of 0 when scrolling the bottom axis? I added codes to Chart->OnScroll event to restrict the bottom axis from 0 and it works when using dragging the right mouse inside the chart space, but dragging the bottom axis did not triger the Chart->OnScroll event.
You can do something like the code below in the OnAfterDraw event.

Code: Select all

Private Sub TChart1_OnAfterDraw()
    If TChart1.Axis.Bottom.Minimum < 0 Then
        TChart1.Axis.Bottom.Minimum = 0
    End If
End Sub
Also, when scroll the graph, the number of the axis's labels (scales) or the inner ticks varies from 5 to 12. Is it possible to have the fixed number of labels (or inner ticks) for the bottom axis displayed?
You can try manually setting Increment and ticks. For more information on how to do that please read Tutorial 4 - Axis Control. Tutorials can be found at TeeChart's program group.
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Post by Xia » Mon Feb 18, 2008 2:26 pm

Hi Narcis,

I added the code as you suggested for the OnAfterDraw event to overcome the problem of negative time axis. It works to some extent. Just when you drag the bottom axis quickly, it shows the negative time axis sometimes. Is there anything I can do to improve this?

For my initial question (see my first email), I have added another custom vertical axis instead of using the standard RightAxis, so the position of the vertical axes will not change when switching from the multi axes (three custom vertical axes in this case) to a single axis (new full range custom vertical axis). This was done by the codes below;

if ( MultiAxes Display )
{
Series1->CustomVertAxis = CustomVertAxis1 // 0-33%
Series2->CustomVertAxis = CustomVertAxis2 // 33-66%
Series3->CustomVertAxis = CustomVertAxis3 // 66-100%
}
else
{
Series1->CustomVertAxis = CustomVertAxis4 // 0-100%
Series2->CustomVertAxis = CustomVertAxis4 // 0-100%
Series3->CustomVertAxis = CustomVertAxis4 // 0-100%
}

I have added codes for OnZoom and OnUndoZoom so it can zoom in/out for the individual custom vertical axis (Axis1-4) by using Chart->Zoom->Y0 and Y1. But I have a problem when scrolling the chart by dragging the right mouse button inside the chart space. Scrolling the chart in the single axis mode (i.e. CustomVertAxis4) will also change CustomVertAxis1-3 in the multi-axis mode. Is it possible to add some codes for OnScroll event so the vertical axes 1-3 in the multi-axes display will not be affected when scrolling chart in the single axis display?

I have also checked your TChart Pro V8 New Features Demo program, All features/Axes/Multiple at Runtime. If you click the Single Axis first and then drag the right mouse button inside the chart space. When you unclick the Single Axis, the vertical axes for series 2 and 3 show as zero. In my program, it sometimes causes Invalid floating point operation error. How can I fix this problem?

Your help would be very much appreciated.

Xia

[/code]

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 Feb 18, 2008 3:37 pm

Hi Xia,
I added the code as you suggested for the OnAfterDraw event to overcome the problem of negative time axis. It works to some extent. Just when you drag the bottom axis quickly, it shows the negative time axis sometimes. Is there anything I can do to improve this?
I'm not able to reproduce the problem here. Could you please let us know the exact steps we should follow or send us a simple example project we can run "as-is" to reproduce the problem here?
I have added codes for OnZoom and OnUndoZoom so it can zoom in/out for the individual custom vertical axis (Axis1-4) by using Chart->Zoom->Y0 and Y1. But I have a problem when scrolling the chart by dragging the right mouse button inside the chart space. Scrolling the chart in the single axis mode (i.e. CustomVertAxis4) will also change CustomVertAxis1-3 in the multi-axis mode. Is it possible to add some codes for OnScroll event so the vertical axes 1-3 in the multi-axes display will not be affected when scrolling chart in the single axis display?


I'm sorry but I don't understand which is the exact problem. Would you be so kind to send us a simple example project we can run "as-is" to reproduce the issue too?

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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Post by Xia » Tue Feb 19, 2008 2:23 pm

Dear Narcis,

I have sent a test program to your upload page. Hopefully, you will be able to reproduce the problems I described, i.e.
1) time scale<0 when dragging the bottom axis quickly.
2) scroll the chart in single-axis display by dragging the right-mouse will also scroll the vertical axes for the multi-axes mode and show axis labels as zero, or visa verse.

One more question, when close or exit the TeeChart program, do I need to delete TeeChart components such as TChartTools, TChartSeries, etc. to free the used memory space?

Looking forwar to hearing from you

Xia

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

Post by Narcís » Tue Feb 19, 2008 2:51 pm

Hi Xia,

Thanks for the example project.

First of all, please notice that I moved this thread from the TeeChart ActiveX forum to the TeeChart VCL one since I've seen you are using TeeChart VCL.

Please find below the answers to your questions:
1) time scale<0 when dragging the bottom axis quickly.
Ok, then moving the code from the OnAfterDraw event to the OnBeforeDrawChart event works fine.
2) scroll the chart in single-axis display by dragging the right-mouse will also scroll the vertical axes for the multi-axes mode and show axis labels as zero, or visa verse.
In that case you could save axes minimun and maximum values before scrolling the chart and restoring them after having scrolled it. Something similar to the code below which does a similar process for zoom.

Code: Select all

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  if Series1Region then
  begin
    With Series1.GetVertAxis do
      SetMinMax(CalcPosPoint(Chart1.Zoom.Y1),CalcPosPoint(Chart1.Zoom.Y0));

    With Series1.GetHorizAxis do
      SetMinMax(CalcPosPoint(Chart1.Zoom.X1),CalcPosPoint(Chart1.Zoom.X0));
  end
  else
  begin
    With Series2.GetVertAxis do
      SetMinMax(CalcPosPoint(Chart1.Zoom.Y1),CalcPosPoint(Chart1.Zoom.Y0));

    With Series2.GetHorizAxis do
      SetMinMax(CalcPosPoint(Chart1.Zoom.X1),CalcPosPoint(Chart1.Zoom.X0));

    Series1.GetVertAxis.Automatic:=true;
    Series1.GetHorizAxis.Automatic := true;
  end;

end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
       Series1.GetVertAxis.Automatic:=true;
       Series1.GetHorizAxis.Automatic := true;
       Series2.GetVertAxis.Automatic:=true;
       Series2.GetHorizAxis.Automatic := true;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
        if (Y <= Series1.GetVertAxis.IEndPos) then
                Series1Region:=true
        else
                Series1Region:=false;
end;
One more question, when close or exit the TeeChart program, do I need to delete TeeChart components such as TChartTools, TChartSeries, etc. to free the used memory space?


No, there's no need to free memory. VCL framework and TeeChart do this automatically.
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

Xia
Newbie
Newbie
Posts: 47
Joined: Tue Oct 16, 2007 12:00 am

Post by Xia » Fri Feb 22, 2008 1:50 pm

Hi Narcis,

Thanks. It works fine.

I am impressed by your technical support.

Regards

Xia

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 Feb 22, 2008 2:11 pm

Hi Xia,
Thanks. It works fine.
You're welcome.
I am impressed by your technical support.
Thank you very much :D.
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