Page 1 of 1

Bug in TErrorBarSeries

Posted: Tue Jun 11, 2013 5:36 am
by 16564851
Hello, I am using TChart 2012.6.120613

TErrorBarSeries seems to have a bug that if I don't specify an error bar size, the bar itself does not appear.

For example, the following code does not show any bars at all

Code: Select all

  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TErrorBarSeries;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  series1.AddErrorBar(1,10,0,'foo',clRed);
  series1.AddErrorBar(2,20,0,'fee',clRed);
end;
but if I change Button1Click to

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  series1.AddErrorBar(1,10,1,'foo',clRed);
  series1.AddErrorBar(2,20,1,'fee',clRed);
end;
then both the bars and the error bars appear. I looked in the release notes and did not see any fixes regarding errorBars. Has this been fixed, or if not, what fix should I apply to my own code.

Re: Bug in TErrorBarSeries

Posted: Wed Jun 12, 2013 1:40 pm
by 10050769
Hello David,

Seems the problem appears in latest version and it occurs only when the Error Value of ErrorBar Series is 0. I have added it in bug list report with number [TV52016601]. We will try to fix it to upcoming versions of TeeChartVCL.


Thanks,

Re: Bug in TErrorBarSeries

Posted: Wed Jun 12, 2013 3:05 pm
by 16464844
Can you please let me know the point in the code to fix it. I will fix it myself. We need this functionality quite a bit, and the user has the option in our software to not show the error bars. In that case, we put them as zero, but now that is making the whole bar disappear.

Re: Bug in TErrorBarSeries

Posted: Thu Jun 13, 2013 9:35 am
by narcis
Hi David,

Most likely the error will be in TCustomErrorSeries.DrawBar method at ErrorBar.pas. A fix suggestion is implementing mentioned method like this:

Code: Select all

Procedure TCustomErrorSeries.DrawBar(BarIndex,StartPos,EndPos:Integer);
Var tmp         : Integer;
    tmpWidth,
    tmpBarWidth : {$IFDEF FMX}Single{$ELSE}Integer{$ENDIF};
    tmpError    : Double;
    tmpHeight   : Integer;
    tmpVal      : Double;
    tmpHeight2  : Integer;
Begin
  tmpError:=FErrorValues.Value[BarIndex];

  if ErrorPen.Visible and (tmpError<>0) then
  Begin
    tmpBarWidth:=BarBounds.Right-BarBounds.Left;

    if FErrorWidth=0 then tmpWidth:=tmpBarWidth
    else
    if FErrorWidthUnits=ewuPercent then
       tmpWidth:=Round(1.0*FErrorWidth*tmpBarWidth*0.01)
    else
       tmpWidth:=FErrorWidth;

    tmpVal:=YValues.Value[BarIndex];
    tmp:=CalcYPosValue(tmpVal);

    { MS : simplified and allows vertical/horizontal style 5.01 }
    Case FErrorStyle of
      essLeft,
      essRight,
      essLeftRight :
      begin
        tmpHeight:=GetHorizAxis.CalcSizeValue(Abs(tmpVal)) -
                    GetHorizAxis.CalcSizeValue(Abs(tmpVal-tmpError));

        if GetHorizAxis.Logarithmic then
          tmpHeight2:=GetHorizAxis.CalcSizeValue(Abs(tmpError+tmpVal)) -
                      GetHorizAxis.CalcSizeValue(Abs(tmpVal))
        else
          tmpHeight2:=tmpHeight;

        if GetHorizAxis.Inverted then
          SwapInteger(tmpHeight, tmpHeight2);
      end;
    else
      begin
        tmpHeight:=GetVertAxis.CalcSizeValue(tmpError+Abs(tmpVal)) -
                      GetVertAxis.CalcSizeValue(Abs(tmpVal));

        if GetVertAxis.Logarithmic then
          tmpHeight2:=GetVertAxis.CalcSizeValue(Abs(tmpVal)) -
                    GetVertAxis.CalcSizeValue(Abs(tmpVal-tmpError))
        else
          tmpHeight2:=tmpHeight;

        if GetVertAxis.Inverted then
          SwapInteger(tmpHeight, tmpHeight2);
      end;
    end;

    if MultiBar=mbStacked100 then   // 7.06 TV52010945
       tmp:=CalcYPosValue(100);

    if IDrawBar and (YValues.Value[BarIndex]<YOrigin) then
    begin
      tmpHeight:=-tmpHeight;

      PrepareErrorPen(BarIndex);

      DrawError((BarBounds.Right+BarBounds.Left) {$IFDEF FMX}*0.5{$ELSE}div 2{$ENDIF},tmp,
                 tmpWidth,tmpHeight,tmpHeight2,ParentChart.View3D);

      inherited;
    end
    else
    begin
      if IDrawBar then
         inherited;

      PrepareErrorPen(BarIndex);

      DrawError((BarBounds.Right+BarBounds.Left) {$IFDEF FMX}*0.5{$ELSE}div 2{$ENDIF},tmp,
                 tmpWidth,tmpHeight,tmpHeight2,ParentChart.View3D);
    end;
  end
  else
  if IDrawBar then
     inherited;
end;
I'll check if there's any other problem with the fix and can be included in the next maintenance release.

Re: Bug in TErrorBarSeries

Posted: Fri Jul 19, 2013 7:15 pm
by 16564851
HI Narcis,

Before we apply this change to the source, is this the final form the fix will take in the next maintenance release?

Re: Bug in TErrorBarSeries

Posted: Mon Jul 22, 2013 7:01 am
by narcis
Hello David,

Yes, that was implemented as the final fix for this issue.

Re: Bug in TErrorBarSeries

Posted: Mon Jul 22, 2013 9:30 pm
by 16564851
Hi Narcis,

In that case, do you know when this release is slated to appear. If its just in a short time, we will just update at that time. If its going to be a long time, we will make the fix and recompile the source.

Re: Bug in TErrorBarSeries

Posted: Tue Jul 23, 2013 7:05 am
by narcis
Hi David,

A date hasn't been confirmed yet. A few days ago a beta version was published. It includes many new features and changes. If you are a source-code customer you should receive an email with information on how to get it.

Re: Bug in TErrorBarSeries

Posted: Tue Jul 23, 2013 1:41 pm
by 16564851
HI Narcis,

And this fix was in the beta?

Re: Bug in TErrorBarSeries

Posted: Tue Jul 23, 2013 1:48 pm
by narcis
Hi David,

Yes.