Page 1 of 1
Problem with right and left axis
Posted: Mon Sep 21, 2009 5:49 pm
by 9526926
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
Re: Problem with right and left axis
Posted: Tue Sep 22, 2009 7:50 am
by yeray
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
Re: Problem with right and left axis
Posted: Wed Sep 23, 2009 4:36 pm
by 9526926
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.
Re: Problem with right and left axis
Posted: Thu Sep 24, 2009 9:24 am
by yeray
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.
Re: Problem with right and left axis
Posted: Tue Oct 27, 2009 5:11 pm
by 9526926
Hi Yeray, thanks for your time
I try again, and the problem is the same
Is possible draw a graph like I want?
Thanks
Re: Problem with right and left axis
Posted: Tue Oct 27, 2009 9:13 pm
by 9526926
Hi Yeray,
I want to draw a graph like that.
Thanks in advance
Re: Problem with right and left axis
Posted: Wed Oct 28, 2009 10:09 am
by yeray
Hi Daniel,
Here is what I'm getting with the code suggested above in TeeChart v8.
I'm afraid I can't think on a way to do this in v7.
Re: Problem with right and left axis
Posted: Wed Oct 28, 2009 4:13 pm
by 9526926
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
Thanks in advance
Re: Problem with right and left axis
Posted: Fri Oct 30, 2009 3:42 pm
by yeray
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;
Re: Problem with right and left axis
Posted: Fri Oct 30, 2009 5:10 pm
by 9526926
Thanks Yeray, I'll update my versiĆ³n ASAP
Could you write to me, an example for anotation tool?
TIA
Daniel
Re: Problem with right and left axis
Posted: Fri Oct 30, 2009 5:35 pm
by 9526926
Hi Yeray
Acutally I use Visual Basic 6.
thanks
Re: Problem with right and left axis
Posted: Mon Nov 02, 2009 8:44 am
by yeray
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
Re: Problem with right and left axis
Posted: Mon Nov 02, 2009 2:47 pm
by 9526926
Hi Yeray,
That's exact why I need
Thanks