Page 1 of 1

strange bar width combining series with different # of data

Posted: Mon Jul 27, 2009 8:58 am
by 10553957
When combining barseries and line series with different # of datapoints, the bar width becomes strange (check attached screenshots and test app). Here's a patch for that 8) :

Code: Select all

Procedure TCustomBarSeries.DoBeforeDrawChart;
<snip>

  for t:=0 to SeriesCount-1 do
{$ifdef HH_PATCH_TC_BARWIDTH}
// THis fixes a problem when using eg mixed stacked bars and a line series. If
// the line series has more datapoints than the barseries, the bars will become
// too wide, because only other barseries are originally checkd for datacount.
// This now also checks other series with YMandatory=True
  if Series[t].Active then
  begin
    if SameClass(Series[t]) then
    begin
      Stop:=Stop or (Series[t]=Self);
      tmp:=Series[t].Count;
      if (IMaxBarPoints=TeeAllValues) or (tmp>IMaxBarPoints) then
         IMaxBarPoints:=tmp;
      Case FMultiBar of
        mbNone: INumBars:=1;
        mbSide,
        mbSideAll: begin
                     Inc(INumBars);
                     if not Stop then Inc(IOrderPos);
                   end;
        mbStacked,
        mbStacked100: if NewGroup(TCustomBarSeries(Series[t]).FStackGroup) then
                      begin
                        Inc(INumBars);
                        if not Stop then Inc(IOrderPos);
                      end;
      end;
      if not Stop then Inc(IPreviousCount,tmp);
    end
    else
    begin
      if Series[t].YMandatory then
      begin
        tmp:=Series[t].Count;
        if (IMaxBarPoints=TeeAllValues) or (tmp>IMaxBarPoints) then
           IMaxBarPoints:=tmp;
      end;

    end;
  end;
{$else}
  if Series[t].Active and SameClass(Series[t]) then
  begin
    Stop:=Stop or (Series[t]=Self);
    tmp:=Series[t].Count;

    if (IMaxBarPoints=TeeAllValues) or (tmp>IMaxBarPoints) then
    begin
      IMaxBarPoints:=tmp;

      if FSideMargins and (tmp>0) then // 7.06
         Inc(IMaxBarPoints);
    end;

    Case FMultiBar of
      mbNone: INumBars:=1;
      mbSide,
      mbSideAll: begin
                   Inc(INumBars);
                   if not Stop then Inc(IOrderPos);
                 end;
      mbStacked,
      mbStacked100: if NewGroup(TCustomBarSeries(Series[t]).FStackGroup) then
                    begin
                      Inc(INumBars);
                      if not Stop then Inc(IOrderPos);
                    end;
      mbSelfStack: INumBars:=1;
    end;

    if not Stop then
       Inc(IPreviousCount,tmp);
  end;
  {$endif}
<snip>
PS Also the bar with becomes strange when setting eg bottomaxis min to 100, max to 1000 and adding a few irrregular datapoints like AddXY(X,Y) (110,100) (120,100) (800,100), but I have no fix for this yet as this is no problem for me at the moment :twisted: ).

Re: strange bar width combining series with different # of data

Posted: Mon Jul 27, 2009 2:19 pm
by yeray
Hi Hans,

I've reproduced and added your fix to the sources so that it will be available in the next maintenance release.

Thank you.