danisius
danisius

Reputation: 597

How to set equal with of point (TpointSeries) to Bar of (TbarSeries) in Steema TChart

I am having a chart that has TBarSeries and TPointSeries at the same time. I want points to have the same width as bars.

What i did without result is:

var S1:TPointSeries;
    S2:TBarSeries;
S1.Pointer.HorizWidth:=S2.BarWidth;

The points actualy bacame nearly twice as bigger as the bars.

Upvotes: 0

Views: 881

Answers (1)

Yeray
Yeray

Reputation: 5039

Note you have to be sure the chart has been drawn at least once to be able to retrieve the TBarSeries BarWidth. Use the TChart's Draw() function to force a chart repaint and then you can safely retrieve the BarWidth.

Also note the TPointSeries Pointer width is the HorizSize * 2. The HorizSize is the length from the center of the point to the left and right sides of the pointer.

Here it is what I get with the code below:

Point and Bar

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var S1:TPointSeries;
    S2:TBarSeries;
begin
  Chart1.View3D:=false;

  S2:=Chart1.AddSeries(TBarSeries) as TBarSeries;
  S1:=Chart1.AddSeries(TPointSeries) as TPointSeries;

  S2.Marks.Visible:=false;

  S1.FillSampleValues(6);
  S2.FillSampleValues(6);

  Chart1.Draw;
  S1.Pointer.HorizSize:=S2.BarWidth div 2;
end;

Upvotes: 2

Related Questions