Draw custom value on y axis
Draw custom value on y axis
Good day,
I am trying to draw my closing value from by candle stick on the Y axis, but with no luck I am getting it right.
I am trying to accomplish the following.
1) By default when my chart is loaded I want to highlight on the Y axis the highest closing value in different color.
2) Secondly if possible can I draw also on the y axis the current closing value if the mouse move over a series.
I already have the closing value on mouse move.
Here is a screen shot with my idea.
I hope this can help.
I am trying to draw my closing value from by candle stick on the Y axis, but with no luck I am getting it right.
I am trying to accomplish the following.
1) By default when my chart is loaded I want to highlight on the Y axis the highest closing value in different color.
2) Secondly if possible can I draw also on the y axis the current closing value if the mouse move over a series.
I already have the closing value on mouse move.
Here is a screen shot with my idea.
I hope this can help.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Draw custom value on y axis
Hi Gucci,
You can achieve what you request using Annotation tools set to a custom position. You can drop a TChart component, add a Candle series and two Annotation tools to it and use the following code:
You can achieve what you request using Annotation tools set to a custom position. You can drop a TChart component, add a Candle series and two Annotation tools to it and use the following code:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=False;
Series1.FillSampleValues();
ChartTool1.Text:=FloatToStr(Series1.CloseValues.MaxValue);
ChartTool1.Shape.Transparent:=True;
ChartTool1.Shape.Font.Color:=clRed;
ChartTool2.Active:=False;
ChartTool2.Shape.Transparent:=True;
ChartTool2.Shape.Font.Color:=clBlue;
Chart1.Draw;
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
SetAnnotationPosition(ChartTool1);
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var Index : Integer;
begin
Index:=Series1.Clicked(X, Y);
ChartTool2.Active:=Index<>-1;
If ChartTool2.Active then
begin
ChartTool2.Text:=FloatToStr(Series1.CloseValues[Index]);
SetAnnotationPosition(ChartTool2);
end;
end;
procedure TForm1.SetAnnotationPosition(Annotation: TAnnotationTool);
var Value : Double;
XPos : Integer;
YPos : Integer;
begin
Value:=StrToFloat(Annotation.Text);
XPos:=Chart1.Axes.Bottom.IStartPos - Annotation.Width -
Chart1.Axes.Left.TickLength - 2;
YPos:=Chart1.Axes.Left.CalcPosValue(Value) - (Annotation.Height div 2);
Annotation.Shape.CustomPosition:=True;
Annotation.Shape.Left:=XPos;
Annotation.Shape.Top:=YPos;
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 |
Instructions - How to post in this forum |
Re: Draw custom value on y axis
Hi,
I dont know what to say, but it is beautiful.
Thanx you so much.
I dont know what to say, but it is beautiful.
Thanx you so much.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Draw custom value on y axis
Hi Gucci,
You're very welcome!
You're very welcome!
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Draw custom value on y axis
Good day support,
Sorry to keep coming back to this, but I am starting to completely loose it with myself. my problem is as follows :
I dynamically create a new function each time and a TAnnotationTool. I am trying on my SetAnnotationPosition to set each closing value to each custom axis created, but this is were I am completely loosing the plot.
I have tried all different ways but cant get it right. Can you please see if you can determine if this is possible.
Sorry to keep coming back to this, but I am starting to completely loose it with myself. my problem is as follows :
I dynamically create a new function each time and a TAnnotationTool. I am trying on my SetAnnotationPosition to set each closing value to each custom axis created, but this is were I am completely loosing the plot.
I have tried all different ways but cant get it right. Can you please see if you can determine if this is possible.
- Attachments
-
- chart dynamic.zip
- (12.34 KiB) Downloaded 751 times
Re: Draw custom value on y axis
Hello,
First of all note you start creating a TCandleSeries with a CustomAxis assigned to it. This is fine if you want but later you are trying to synchronize tools with custom axes and this would be cleaner if you have as many custom axes as annotation tools. So I start removing the initial custom axis assigned to the TCandleSeries.
I also removed the SetAnnotationPosition method and I'm recalculating the positions of the annotations at the calculateaxis. I'm doing this way because the new positions of the axes should also alter the positions of all the annotations.
Here how it looks: And the project modified:
First of all note you start creating a TCandleSeries with a CustomAxis assigned to it. This is fine if you want but later you are trying to synchronize tools with custom axes and this would be cleaner if you have as many custom axes as annotation tools. So I start removing the initial custom axis assigned to the TCandleSeries.
I also removed the SetAnnotationPosition method and I'm recalculating the positions of the annotations at the calculateaxis. I'm doing this way because the new positions of the axes should also alter the positions of all the annotations.
Here how it looks: And the project modified:
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Draw custom value on y axis
Thank you much for the nice and clean solution, what do you suggest I must do with the CandleSeries closing value. Must I create a seperate calculation or do you suggest I use your current calculateaxis to add that value in.
thank you again.
Re: Draw custom value on y axis
Hello,
I see Narcís suggested you to have two extra TAnnotationTools, one always visible (showing the maximum close value) and one visible when the mouse is over the candle series (showing the close value of the candle under the mouse).
That code wasn't present on the project you attached so I skipped that part, but of course you can re-add it. Just note these two extra annotation tools will also be in Chart1.Tools array, so you'll have to take care with the indexes at calculateaxis (use Chart1.Tools.Items[i+2] instead of Chart1.Tools.Items).
Don't hesitate to let us know if you find problems with it.
I see Narcís suggested you to have two extra TAnnotationTools, one always visible (showing the maximum close value) and one visible when the mouse is over the candle series (showing the close value of the candle under the mouse).
That code wasn't present on the project you attached so I skipped that part, but of course you can re-add it. Just note these two extra annotation tools will also be in Chart1.Tools array, so you'll have to take care with the indexes at calculateaxis (use Chart1.Tools.Items[i+2] instead of Chart1.Tools.Items).
Don't hesitate to let us know if you find problems with it.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Draw custom value on y axis
Hi Yeray
I am not 100% sure If I understand your solution, is it possible you can alter your last example attached.
Thank you so much
I am not 100% sure If I understand your solution, is it possible you can alter your last example attached.
Thank you so much
Re: Draw custom value on y axis
Hi,
Take a look at it:
Take a look at it:
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Draw custom value on y axis
Thank you so much. Money well spend on a great tool and support.