problem with TErrorSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
davidnovo
Newbie
Newbie
Posts: 15
Joined: Mon Nov 30, 2009 12:00 am

problem with TErrorSeries

Post by davidnovo » Tue Apr 20, 2010 9:30 pm

Hello,

I am creating a TPointSeries and TErrorSeries to show error bars on top of a point series. I create the X,Y coordinates of each one the same, and just give the error bar a value for the bar height. This works fine if I have just one point series and one errorSeries. However, If I have two pointseries and two errorseries, the error bars are drawn offset.

I have a attached a sample application demonstrating the issue. If you can please let me know how to fix it I will apply the patch to our own copy of TChart.
We are using TChart 8.04. In the same app run it once with the checkbox off, and the next time with the checkbox on. You will see the error bars are not drawn correctly in the latter case.
Attachments
errorbars.zip
(400.48 KiB) Downloaded 770 times

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

Re: problem with TErrorSeries

Post by Yeray » Wed Apr 21, 2010 2:44 pm

Hi davidnovo,

When there are two TErrorSeries, the ErrorBars in the same XValue are drawn one next to the other. Do you mean you would like the ErrorBars in the same XValue to be drawn one over the other, with overlapping?
Doing like this they won't overlap:

Code: Select all

uses ErrorBar, Series;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.View3D:=false;

  for i:=0 to 3 do with Chart1.AddSeries(TErrorSeries.Create(self)) as TErrorSeries do
    for j:=0 to 3 do AddErrorBar(j,random*10,5);
end;
If you want to draw the ErrorBars in the same XValue, you could use a unique TErrorSeries:

Code: Select all

uses ErrorBar, Series, TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.View3D:=false;

  with Chart1.AddSeries(TErrorSeries.Create(self)) as TErrorSeries do
    for i:=0 to 3 do
      for j:=0 to 3 do AddErrorBar(j,random*100,random*5,'',OperaPalette[i]);
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

davidnovo
Newbie
Newbie
Posts: 15
Joined: Mon Nov 30, 2009 12:00 am

Re: problem with TErrorSeries

Post by davidnovo » Wed Apr 21, 2010 3:28 pm

Hi Yeray,

I am afraid I do not understand. I would kindly ask that you look at the sample application that I sent you. In that application, I create 2 unique error series. The error series have the same x values as each other, but different Y values. They are also the same X,Y values as the point series.

The error series should be drawn on TOP of the point series. i.e. each error bar should be drawn ON TOP of each point. This is because each point and each error series have the same X,Y values. This does happen is there is only one TPointSeries and one TErrorSeries. If there are two TPointSeries and two TErrorSeries then it does not work.

I spent quite a bit of effort debugging this and creating a test app for you that duplicates the error. Please have a look at the attached project. I need to know how if I have two TPointSeries, I can draw an error bar ON TOP of each point, even if some of the points share the same X Value.

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

Re: problem with TErrorSeries

Post by Yeray » Wed Apr 21, 2010 3:44 pm

Hi davidnovo,

Excuse me if I haven't expressed myself enough clearly. Of course I've seen your application before answering. What I tried to explain is the issue that I understand is behind your problem.
Try to forget for one moment the TPointSeries. Having a TErrorSeries with XValues 0, 1, 2,... the ErrorBars are drawn exactly in the X=0, X=1,... but when you have two TErrorSeries, they are drawn one next to the other so the first is drawn some pixels at the left side of X=0, X=1,... and the second TErrorSeries is drawn some pixels at the right side of X=0, X=1,... This is made to fit as many TErrorSeries as one would like to draw without overlapping.
On the other hand, TPointSeries doesn't do this job. They don't prevent this overlapping.

So, before proceeding with proposing you a workaround, we would need to know if you want your TErrorSeries to overlap or you want them to be drawn side by side for each XValue.
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

davidnovo
Newbie
Newbie
Posts: 15
Joined: Mon Nov 30, 2009 12:00 am

Re: problem with TErrorSeries

Post by davidnovo » Wed Apr 21, 2010 5:51 pm

Hello,

Thank you. I definately want them to "overlap", because, they are not really overlapping. Even though the X values are the same, the Y values are totally different.

I can see this auto-adjusting to eliminate X-overlap can be a useful feature, but should not be the default behaviour. In AddErrorBar I specify the X,Y and I want the error bar drawn at that X,Y. Perhaps if there was a property on the TErrorSeries called PreventOverlapWithOtherErrorBars that could be cool, but I definately don't want that.

Based on your previous comments, I presume you are going to suggest to put all the error bars in a single error series. If there is another way to make the error bars "overlap" without having to do this, that would be great.

It is also not that easy for me to create a single errorSeries with all the error bars from multiple data sets. Each set of PointSers/ErrorSeries comes from a separate SeriesBuilder Object that we have. The SeriesBuilder objects do not know if other series are going to be created or not. They just know that they have to build a PointSeries and an ErrorBarSeries for the data that they happen to contain.

If I can only add the points to a single error series I will have to rearchitect things quite a bit to allow communication between the different seriesBuilders which is quite a bit of effort.

davidnovo
Newbie
Newbie
Posts: 15
Joined: Mon Nov 30, 2009 12:00 am

Re: problem with TErrorSeries

Post by davidnovo » Wed Apr 21, 2010 5:54 pm

Hello,

To be cleared, I cannot "forget" about the TPointSeries. Each Point+Error bar represents a mean +SD of a particular measurement. The error bar ALWAYS has to be on top of its corresponding point, no matter how far the points/error bars are away from each other. If the points or error bars are too close to each other, well, that is just the way it is.

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

Re: problem with TErrorSeries

Post by Yeray » Thu Apr 22, 2010 7:28 pm

Hi davidnovo,

I've tried another idea different from using TPointSeries: Custom drawing directly to the canvas. In a first thought I wasn't sure if the CalcXPos method would return the position with the "offset" or not. Finally it seems to work fine:

Code: Select all

uses series, ErrorBar;

var PointerSize: integer;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;

  for i:=0 to 1 do
  begin
    Chart1.AddSeries(TErrorSeries.Create(self));
    Chart1[i].FillSampleValues();
  end;

  PointerSize:=6;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i, j, XCenter, YCenter: Integer;
begin
  for i:=0 to Chart1.SeriesCount-1 do
    with Chart1[i] as TErrorSeries do
      for j:=0 to Count-1 do
      begin
        XCenter:=CalcXPos(j) + ((BarBounds.Right+BarBounds.Left) div 2 - BarBounds.Left);
        YCenter:=CalcYPos(j);
        if PtInRect(Chart1.ChartRect,Point(XCenter,YCenter)) then
        begin
          Chart1.Canvas.Brush.Color:=Color;
          Chart1.Canvas.Rectangle(XCenter - (PointerSize div 2), YCenter - (PointerSize div 2), XCenter + (PointerSize div 2), YCenter + (PointerSize div 2));
        end;
      end;
end;
Anyway, I'll add to the wish list the possibility to add a property like PreventOverlapWithOtherErrorBars (or a shorter name :wink:) to permit choosing between using the automatic offset or not (TV52014830).
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

dave novo
Newbie
Newbie
Posts: 25
Joined: Tue Oct 23, 2007 12:00 am

Re: problem with TErrorSeries

Post by dave novo » Thu Apr 22, 2010 11:11 pm

Hi Yeray,

Thanks for the prompt response!

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

Re: problem with TErrorSeries

Post by Yeray » Fri Apr 23, 2010 7:17 am

Hi davidnovo,

You're welcome!
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

Post Reply