THistogramSeries % Bar Width

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

THistogramSeries % Bar Width

Post by Toreba » Wed Apr 20, 2016 5:13 pm

Hi,

What does this property do? Setting it to 100% produces bars that overlap. The value I need to obtain non-overlapping bars is much less than this, but varies according to the zoom. What does 100% mean? There seems not to be any help for this class. I'm using in TeeChart Pro v2014.12.140923 32-bit VCL in XE7.

Regards

Toreba

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

Re: THistogramSeries % Bar Width

Post by Yeray » Thu Apr 21, 2016 1:42 pm

Hello Toreba,

Could you please arrange a simple example project showing us what are you exactly doing?
Thanks in advance.
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

Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

Re: THistogramSeries % Bar Width

Post by Toreba » Mon Apr 25, 2016 3:35 pm

Yeray,

I'm sorry, I was wrong (again). THistogramSeries works fine, and doesn't offer a % bar width property. It is In fact TBarSeries for which the property makes no sense. Do you agree with that?

Regards

Toreba

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

Re: THistogramSeries % Bar Width

Post by Yeray » Tue Apr 26, 2016 7:53 am

Hello Toreba,

There are 3 properties with similar names that could be confusing you. From the online docs:
TCustomBarSeries.BarWidthPercent wrote:TCustomBarSeries.BarWidthPercent
TCustomBarSeries
property BarWidthPercent: Integer;

Unit
Series

Description
Default Value: 70

The BarWidthPercent property determines the percent of total Bar width used. Setting BarWidthPercent := 100 makes joined Bars. You can control how many Bars appear at same time by using TChart.MaxPointsPerPage property. The BarWidth and BarHeight properties indicate Bar dimensions in pixels.
TBarSeries.BarWidth wrote:TBarSeries.BarWidth
TBarSeries
property BarWidth: Integer;

Unit
Series

Description
Run time and read only. The BarWidth property returns the width of vertical Bars in pixels. Bar widths change at run-time when resizing or zooming the Chart. BarWidth is a read-only property. You can use the CustomBarWidth property to set a fixed pixels Bar width.
TBarSeries.CustomBarWidth wrote:TBarSeries.CustomBarWidth
TBarSeries
property CustomBarWidth: Integer;

Unit
Series

Description
Default: 0
The CustomBarWidth property determines the fixed Bar width in pixels. You can use the BarWidth property to get the current Bar width in pixels.
Which one doesn't behave as you'd expect?
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

Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

Re: THistogramSeries % Bar Width

Post by Toreba » Wed Apr 27, 2016 1:47 pm

Yeray,

I think it's the first of these properties that doesn't work, at least using v2014.12.140923 32-bit in XE7. It's easy to show with a simple demo. Do you need me to provide one?

Regards

Toreba

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

Re: THistogramSeries % Bar Width

Post by Yeray » Fri Apr 29, 2016 11:30 am

Hi toreba,

This is what I get with v2012.14 and the code below:
testBarWidthPercent.png
testBarWidthPercent.png (14.14 KiB) Viewed 29862 times

Code: Select all

uses Series, TeeConst;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Title.Text.Text:=TeeMsg_Version;
  Chart1.View3D:=false;

  with Chart1.AddSeries(TBarSeries) as TBarSeries do
  begin
    FillSampleValues();

    BarWidthPercent:=100;
  end;
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

Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

Re: THistogramSeries % Bar Width

Post by Toreba » Wed May 04, 2016 1:31 pm

Yeray,

Yes, I get the same, but see what happens when you zoom in. The bar width in pixels seems to remain unchanged, so then fills less than 100% of the gap between the adjacent bars either side. When you have a lot of points and zoom in a long way to the detail, the effect is at its worst. That's what I need to correct. Is there a combination of properties that would do that? Or is it a bug?

Regards

Toreba.

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

Re: THistogramSeries % Bar Width

Post by Yeray » Thu May 05, 2016 9:07 am

Hello Toreba,

Adding this, the BarWidthPercent property works better when zooming also:

Code: Select all

AutoBarSize:=true;
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

LNS
Newbie
Newbie
Posts: 7
Joined: Thu Jul 03, 2014 12:00 am

Re: THistogramSeries % Bar Width

Post by LNS » Wed Aug 24, 2016 11:39 am

We experience a similar problem for TBarSeries where the bar widths are not aligned according to the preset BarWidthPercent when the x-axis is not set to automatic, i.e. does not show all existing values in the series. See the image below.
wrong.png
wrong.png (9.83 KiB) Viewed 29675 times
The settings are:
  • BarWidthPercent set to 70%
  • Bottom Axis with manual Minimum/Maximum, i.e. non-automatic mode. The intention is to display the values with respect to the current time (illustrated by the vertical ColorLineTool), i.e. it is a "moving window" where the axis bounds are frequently updated to focus the current time.
What we would expect is a result as shown below:
working.png
working.png (10.16 KiB) Viewed 29675 times
We achieved this by adding some code to TBarSeries.DoBeforeDrawChart (I omitted some local procedures to make it easier readable):

Code: Select all

Procedure TCustomBarSeries.DoBeforeDrawChart;
var t    : Integer;
    Stop : Boolean;
    tmp  : Integer;
    tmpNonMandatoryAxisRange : Double;
    tmpValueStepPerBar: Double;
const cstAutoCalcBarPointsByBarSteps = True;
begin
  inherited;

  IBarSize:=0;
  IOrderPos:=1;
  IPreviousCount:=0;
  INumBars:=0;
  IMaxBarPoints:=TeeAllValues;
  Groups:=nil;
  Stop:=False;

  With ParentChart do
  for t:=0 to SeriesCount-1 do
  if Series[t].Active then
  begin
    if SameClass(Series[t]) and SameMandatoryAxis(Series[t]) then
    begin
      Stop:=Stop or (Series[t]=Self);
      tmp:=Series[t].Count;

      // ARC ///////////////////////////////////////////////////////////////////
      // Calculate "visible" Bar Points based on their "step width" between two bars compared to visible axis range
      if cstAutoCalcBarPointsByBarSteps and (NotMandatoryAxis.Automatic=False) then
      begin
        tmpNonMandatoryAxisRange:=NotMandatoryAxis.Maximum-NotMandatoryAxis.Minimum;
        if (tmp>1) and (tmpNonMandatoryAxisRange>0) then
        begin
          tmpValueStepPerBar:=Series[t].NotMandatoryValueList.Range/(tmp-1); // -1 since we want the step BETWEEN two bars
          tmp:=Round(tmpNonMandatoryAxisRange/tmpValueStepPerBar)+1; // +1 since the last bar also requires space
        end;
      end;
      //////////////////////////////////////////////////////////////////////////

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

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

      Case FMultiBar of
        mbNone: INumBars:=1;
        mbSide,
        mbSideAll,
        mbSelfStack:
                   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;
  end;

  for t:=0 to Length(Groups)-1 do
  if Groups[t]=FStackGroup then
  begin
    IOrderPos:=t+1;
    break;
  end;

  Groups:=nil;

  if INumBars=0 then
     INumBars:=1;
     
  { this should be after calculating INumBars }
  if FMultiBar=mbSelfStack then
     if ParentChart.MaxPointsPerPage=0 then
        IMaxBarPoints:=INumBars
     else
        IMaxBarPoints:=ParentChart.MaxPointsPerPage

  else
  if ParentChart.MaxPointsPerPage>0 then
     IMaxBarPoints:=ParentChart.MaxPointsPerPage;

  if (ParentChart.MaxPointsPerPage>0) and FSideMargins and (IMaxBarPoints>0) then
     Inc(IMaxBarPoints);
end;
We would appreciate if this or a similar functionality could be integrated into the standard code to make it available for other users.

Kind regards,
Linus

PS: I also attached a simple demo project containing the example above:
Bar Series Width.zip
(5.38 KiB) Downloaded 1666 times

Marc
Site Admin
Site Admin
Posts: 1266
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: THistogramSeries % Bar Width

Post by Marc » Fri Aug 26, 2016 10:17 am

Hello Linus,

That looks useful, thank you for the contribution. We'll run a few checks and include it in the product code.

Thanks again.
Regards,
Marc Meumann
Steema Support

LNS
Newbie
Newbie
Posts: 7
Joined: Thu Jul 03, 2014 12:00 am

Re: THistogramSeries % Bar Width

Post by LNS » Fri Aug 26, 2016 2:47 pm

Hello Marc,

thanks for the prompt and positive feedback. Happy to contribute - and after all, we're of course very interested to use the standard code base without having to merge any customisations of ours when installing a TeeChart update ... :D

Have a nice weekend,
Linus

Post Reply