TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
SSWang
- Newbie
- Posts: 10
- Joined: Mon Mar 14, 2011 12:00 am
Post
by SSWang » Mon Nov 28, 2011 2:00 am
Dear Steema support,
I'm using TFastLineSeries and TBarSeries to implement a MACD chart.
I tried to paint bars with different colors in BarStyle Event but the SeriesColor property
is wrong every time the bar direction invert.
How can I correct this problem? thank you.
Code: Select all
procedure InternalBarStyleEvent(Sender: TCustomBarSeries; ValueIndex: Integer; var TheBarStyle: TBarStyle);
begin
if Sender.YValues[ValueIndex] >= 0 then
begin
Sender.Pen.Color := clRed;
Sender.SeriesColor := clRed;
end else
begin
Sender.Pen.Color := clLime;
Sender.SeriesColor := clLime;
end;
end;
-
Attachments
-
- 2.gif (9.07 KiB) Viewed 20564 times
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Nov 29, 2011 12:41 pm
Hello,
Right, when OnBarStyle event is executed, the brush color is already assigned for the current point so it doesn't take effect until the next point is going to be drawn.
Why don't you set a color for each bar in the series ValueColor array? With it, you only have to set the pen color at the OnBarStyle event.
Code: Select all
with Chart1[0] do
for i:=0 to Count-1 do
if YValue[i] >= 0 then
ValueColor[i]:=clRed
else
ValueColor[i]:=clLime;
-
SSWang
- Newbie
- Posts: 10
- Joined: Mon Mar 14, 2011 12:00 am
Post
by SSWang » Thu Dec 01, 2011 2:24 am
I got it, thanks!
Would you please answer 2 more questions I got here?
1. Can I put 5 serieses and 2 legends A and B in a chart, while legend A shows first 2 of 5 series and legend B shows rest 3 of 5?
2. Can I paint areas under or over certain threshold line, as the attached image does? I found a similar tool from demo app but it paints both areas under and over a threshold line, not just single-sided.
-
Attachments
-
- threshold lines.gif (4.37 KiB) Viewed 20403 times
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Mon Dec 05, 2011 10:00 am
Hi SSWang,
1. Can I put 5 serieses and 2 legends A and B in a chart, while legend A shows first 2 of 5 series and legend B shows rest 3 of 5?
Yes, you can use custom legend tools as Yeray explained
here.
2. Can I paint areas under or over certain threshold line, as the attached image does? I found a similar tool from demo app but it paints both areas under and over a threshold line, not just single-sided.
There's no built-in specific functionality to do that but it can be achieved combining different TeeChart features. We will try to arrange an example project ASAP.
-
SSWang
- Newbie
- Posts: 10
- Joined: Mon Mar 14, 2011 12:00 am
Post
by SSWang » Tue Dec 06, 2011 12:40 am
Thanks, it will be very helpful to have a demo project to achieve this feature.
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Tue Dec 06, 2011 11:27 am
Hi SSWang,
Find attached an example project doing something similar to what you requested.
-
Attachments
-
- ColorRegions.zip
- (2.52 KiB) Downloaded 882 times
-
johnnix
- Advanced
- Posts: 192
- Joined: Tue Jul 10, 2007 12:00 am
Post
by johnnix » Thu Dec 08, 2011 7:05 am
Hello Narcis,
Would it be possible for you to arrange an example for Horizontal Line Series? I tried to implement this solution to a chart with THorizLineSeries but it looks like the CrossPoint function fails to find the cross points?
Regards
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Mon Dec 12, 2011 10:49 am
Hi johnnix,
Find attached the horizontal version.
-
Attachments
-
- HorizColorRegions.zip
- (2.6 KiB) Downloaded 828 times
-
johnnix
- Advanced
- Posts: 192
- Joined: Tue Jul 10, 2007 12:00 am
Post
by johnnix » Tue Dec 13, 2011 7:44 am
Hello Narcis,
Thank you very much for this. I tested it here under D2007 and TeeChart 2011.03.30407 and is some cases it does not work as expected (see attached picture). Can you please confirm this?
Regards
-
Attachments
-
- Untitled-1.gif (12.73 KiB) Viewed 20299 times
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Dec 13, 2011 9:27 am
Hello,
johnnix wrote:I tested it here under D2007 and TeeChart 2011.03.30407 and is some cases it does not work as expected (see attached picture). Can you please confirm this?
Right. There was a problem in the CrossPoints function (concretely at TCrossPointsFunction.AddPoints method) that was giving some wrong points. I've just revised and fixed it for the next maintenance release (TV52015960).
For those source code customers who are interested, the change is simple. In StatChar.pas, method TCrossPointsFunction.AddPoints, change the line:
Code: Select all
until (index1>=tmpX1.Count) or (index2>=tmpX2.Count);
for this:
Code: Select all
until (index1>=tmpX1.Count-1) or (index2>=tmpX2.Count-1);
-
johnnix
- Advanced
- Posts: 192
- Joined: Tue Jul 10, 2007 12:00 am
Post
by johnnix » Tue Dec 13, 2011 9:40 am
Great, I will test that and let you know if anything else comes up
Regards
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Dec 13, 2011 10:46 am
Hi,
Thank you Johnnix
-
johnnix
- Advanced
- Posts: 192
- Joined: Tue Jul 10, 2007 12:00 am
Post
by johnnix » Thu Dec 15, 2011 7:37 am
Hello,
I tried to modify the example so that it can work with 2 Horizontal lines series but it does not work as expected. Is it too much to ask for a sample code? I need to paint the hatched region only. Maybe this could also included in the Tools section?
Regards
-
Attachments
-
- untitled-1.gif (12.52 KiB) Viewed 20247 times
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Thu Dec 15, 2011 11:23 am
Hello Johnnix,
I'm afraid the TSeriesBandTool doesn't differentiate the regions where the first series is greater than the regions where it's lower. I've added to the wish list the possibility to add two brushes to this tool. One brush would be used to draw the "positive" polygon and the other to draw the "negative" polygon (TV52015967).
This would allow you to set one of the brushes to bsClear, that, if I understood well, would fit your requirement.
In the meanwhile, I'm afraid you should calculate the region polygon and draw it manually. You could use the CalcXPos and CalcYPos methods to get the polygon points, and you could calculate the cross point(s) using the TCrossPointsFunction in a similar way than in the examples above.