Page 1 of 1

A problem with bar color, please help.

Posted: Mon Nov 28, 2011 2:00 am
by 16558750
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;

Re: A problem with bar color, please help.

Posted: Tue Nov 29, 2011 12:41 pm
by yeray
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;

Re: A problem with bar color, please help.

Posted: Thu Dec 01, 2011 2:24 am
by 16558750
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.

Re: A problem with bar color, please help.

Posted: Mon Dec 05, 2011 10:00 am
by narcis
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.

Re: A problem with bar color, please help.

Posted: Tue Dec 06, 2011 12:40 am
by 16558750
Thanks, it will be very helpful to have a demo project to achieve this feature.

Re: A problem with bar color, please help.

Posted: Tue Dec 06, 2011 11:27 am
by narcis
Hi SSWang,

Find attached an example project doing something similar to what you requested.

Re: A problem with bar color, please help.

Posted: Thu Dec 08, 2011 7:05 am
by 10046032
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

Re: A problem with bar color, please help.

Posted: Mon Dec 12, 2011 10:49 am
by narcis
Hi johnnix,

Find attached the horizontal version.

Re: A problem with bar color, please help.

Posted: Tue Dec 13, 2011 7:44 am
by 10046032
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

Re: A problem with bar color, please help.

Posted: Tue Dec 13, 2011 9:27 am
by yeray
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);

Re: A problem with bar color, please help.

Posted: Tue Dec 13, 2011 9:40 am
by 10046032
Great, I will test that and let you know if anything else comes up :)

Regards

Re: A problem with bar color, please help.

Posted: Tue Dec 13, 2011 10:46 am
by yeray
Hi,

Thank you Johnnix

Re: A problem with bar color, please help.

Posted: Thu Dec 15, 2011 7:37 am
by 10046032
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

Re: A problem with bar color, please help.

Posted: Thu Dec 15, 2011 11:23 am
by yeray
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.