Problem with right and left axis

TeeChart for ActiveX, COM and ASP
Post Reply
Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Problem with right and left axis

Post by Daniel » Mon Sep 21, 2009 5:49 pm

Hi!!
Actually I use Teechart 7 version and Visual Basic 6. I need draw two series, one of them a bar style in left axis, and the other line style in right axis. I need a graph similar to image (attach), is this possible? And I can set the number of points in the scale? (In this example 6 points), because when set min and max values por left and right scale, the rght scale don't start in the bottom axis, and the graph have difent lines in left and riight axis. Thanks in advance
Attachments
DemoGraph.jpg
Example
DemoGraph.jpg (46.25 KiB) Viewed 13157 times

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

Re: Problem with right and left axis

Post by Yeray » Tue Sep 22, 2009 7:50 am

Hi Daniel,

You could use custom labels to do this. For example, this seems to end similar than what you described:

Code: Select all

Private Sub Form_Load() 
  TChart1.Aspect.View3D = False
  
  TChart1.AddSeries scBar
  TChart1.AddSeries scLine
  
  Dim i As Integer
  For i = 0 To 25
    TChart1.Series(0).Add Rnd * 5, "", clTeeColor
    TChart1.Series(1).Add (Rnd * 0.25) + 2.6, "", clTeeColor
  Next i
   
  TChart1.Series(0).Marks.Visible = False
  TChart1.Series(0).asBar.BarWidthPercent = 25
  
  TChart1.Series(1).Pen.Width = 2
  
  
  TChart1.Series(0).VerticalAxis = aLeftAxis
  TChart1.Series(1).VerticalAxis = aRightAxis
  TChart1.Axis.Left.SetMinMax 0, 6
  TChart1.Axis.Right.SetMinMax 2.5, 2.9

  TChart1.Environment.InternalRepaint
End Sub

Private Sub DrawRighAxisCustomLabels()
  Dim i As Integer
  Dim YValue As Double
  
  With TChart1.Axis
    .Right.Labels.Clear
    For i = 0 To .Left.Labels.Count - 1
      YValue = .Right.CalcPosPoint(.Left.CalcYPosValue(.Left.Labels.Item(i).Value))
      .Right.Labels.Add YValue, Format$(YValue, "#.###")
    Next i
  End With
End Sub

Private Sub TChart1_OnAfterDraw()
  DrawRighAxisCustomLabels
End Sub
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

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Wed Sep 23, 2009 4:36 pm

Hi Yeray,
Thanks for your reply. I try your solution, but not fix my problem. I need, equal lines in right and left axis, i will attach an image with the example. And other question, I can set the number of intervals in the graph? I changed the increment value in the left and right axis calculating this value (in other example), but the right axis not start in the bottom axis, and the lines in left and right axis is not equal. Thanks for your time and patience.
Attachments
DemoGraph.jpg
Graph Demo
DemoGraph.jpg (48.66 KiB) Viewed 13076 times

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

Re: Problem with right and left axis

Post by Yeray » Thu Sep 24, 2009 9:24 am

Hi Daniel,

Excuse me. I missed a line at the end of Form_Load method:

Code: Select all

TChart1.Environment.InternalRepaint
Now I corrected the code above too.
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

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Tue Oct 27, 2009 5:11 pm

Hi Yeray, thanks for your time
I try again, and the problem is the same
:(

Is possible draw a graph like I want?
Thanks

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Tue Oct 27, 2009 9:13 pm

Hi Yeray,
I want to draw a graph like that.
Thanks in advance
Attachments
Mple.jpg
Mple.jpg (22.62 KiB) Viewed 13026 times

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

Re: Problem with right and left axis

Post by Yeray » Wed Oct 28, 2009 10:09 am

Hi Daniel,

Here is what I'm getting with the code suggested above in TeeChart v8.
Image

I'm afraid I can't think on a way to do this in v7.
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

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Wed Oct 28, 2009 4:13 pm

Hi Yeray
Is true, I tried in v8 and work fine. Thanks. I'll update my version
I have another two questions
- Is possible create a graph, with comments in a few points? (like picture1)
- If I have a graph with logarithmic scale, how can I controll the number of points in a scale, for example if I want only 3 points (like pincture 2)
Thanks for your time, if this two graphs work fine, I'll update my version asap :D
Thanks in advance
Attachments
DemoGraph.jpg
Picture 1
DemoGraph.jpg (91.67 KiB) Viewed 13015 times
DemoGraph2.jpg
Picture 2
DemoGraph2.jpg (32.15 KiB) Viewed 13009 times

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

Re: Problem with right and left axis

Post by Yeray » Fri Oct 30, 2009 3:42 pm

Hi Daniel,
Daniel wrote:- Is possible create a graph, with comments in a few points? (like picture1)
Yes, you can use annotation tools and you can update their positions at OnAfterDraw event if you want them to be repositioned each time the chart is redrawn.
Daniel wrote:- If I have a graph with logarithmic scale, how can I controll the number of points in a scale, for example if I want only 3 points (like pincture 2)
Do you mean the left axis labels? You can use custom labels, for example:

Code: Select all

uses series, teetools;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.MarginLeft:=10;
  Chart1.AddSeries(TFastLineSeries.Create(self));
  Chart1.Axes.Left.Logarithmic:=true;
  Chart1[0].FillSampleValues(100);

  with Chart1.Axes.Left.Items do
  begin
    Clear;
    Add(Chart1[0].YValues.MinValue);
    Add(Chart1[0].YValues.MinValue + Chart1[0].YValues.MaxValue / 2);
    Add(Chart1[0].YValues.MaxValue);
  end;

  Chart1.Tools.Add(TAnnotationTool.Create(self));
  Chart1.Tools.Add(TAnnotationTool.Create(self));

  (Chart1.Tools[0] as TAnnotationTool).Text:='point 25 info';
  (Chart1.Tools[1] as TAnnotationTool).Text:='point 75 info';

  Chart1.Draw;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  (Chart1.Tools[0] as TAnnotationTool).Left:=Chart1[0].CalcXPos(25);
  (Chart1.Tools[0] as TAnnotationTool).Top:=Chart1[0].CalcYPos(25);

  (Chart1.Tools[1] as TAnnotationTool).Left:=Chart1[0].CalcXPos(75);
  (Chart1.Tools[1] as TAnnotationTool).Top:=Chart1[0].CalcYPos(75);
end;
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

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Fri Oct 30, 2009 5:10 pm

Thanks Yeray, I'll update my versión ASAP
Could you write to me, an example for anotation tool?
TIA
Daniel

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Fri Oct 30, 2009 5:35 pm

Hi Yeray
Acutally I use Visual Basic 6.
thanks

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

Re: Problem with right and left axis

Post by Yeray » Mon Nov 02, 2009 8:44 am

Hi Daniel,

Here it is the above example translated to VB6:

Code: Select all

Private Sub Form_Load() 
  TChart1.Aspect.View3D = False
  TChart1.Panel.MarginLeft = 10
  TChart1.AddSeries scFastLine
  TChart1.Axis.Left.Logarithmic = True
  TChart1.Series(0).FillSampleValues 100
  
  With TChart1.Axis.Left.Labels
    .Clear
    .Add TChart1.Series(0).YValues.Minimum, Str$(TChart1.Series(0).YValues.Minimum)
    .Add TChart1.Series(0).YValues.Minimum + TChart1.Series(0).YValues.Maximum / 2, Str$(TChart1.Series(0).YValues.Minimum + TChart1.Series(0).YValues.Maximum / 2)
    .Add TChart1.Series(0).YValues.Maximum, Str$(TChart1.Series(0).YValues.Maximum)
  End With

  TChart1.Tools.Add tcAnnotate
  TChart1.Tools.Add tcAnnotate

  With TChart1.Tools.Items(0).asAnnotation
    .Text = "point 25 info"
    .Callout.Visible = True
    .Callout.Arrow.Visible = True
    .Callout.Style = psNothing
    .Callout.Arrow.Color = vbBlack
  End With
  
  With TChart1.Tools.Items(1).asAnnotation
    .Text = "point 75 info"
    .Callout.Visible = True
    .Callout.Arrow.Visible = True
    .Callout.Style = psNothing
    .Callout.Arrow.Color = vbBlack
  End With

  TChart1.Environment.InternalRepaint
End Sub


Private Sub TChart1_OnAfterDraw()
  With TChart1.Tools.Items(0).asAnnotation
    .Left = TChart1.Series(0).CalcXPos(25) + 10
    .Top = TChart1.Series(0).CalcYPos(25) + 10
    .Callout.XPosition = TChart1.Series(0).CalcXPos(25)
    .Callout.YPosition = TChart1.Series(0).CalcYPos(25)
  End With
  
  With TChart1.Tools.Items(1).asAnnotation
    .Left = TChart1.Series(0).CalcXPos(75) + 10
    .Top = TChart1.Series(0).CalcYPos(75) + 10
    .Callout.XPosition = TChart1.Series(0).CalcXPos(75)
    .Callout.YPosition = TChart1.Series(0).CalcYPos(75)
  End With
End Sub
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

Daniel
Newbie
Newbie
Posts: 8
Joined: Wed May 18, 2005 4:00 am

Re: Problem with right and left axis

Post by Daniel » Mon Nov 02, 2009 2:47 pm

Hi Yeray,
That's exact why I need
Thanks

Post Reply