How to place a 'point' on a horizontal bar graph.

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
VideoTrack
Newbie
Newbie
Posts: 17
Joined: Thu Jan 04, 2018 12:00 am

How to place a 'point' on a horizontal bar graph.

Post by VideoTrack » Tue Oct 09, 2018 11:08 am

I want to draw a horizontal bar graph series and draw one of more points at some location over the horizontal bar.
The bars work fine until I want to add the points, and then only every second bar is displayed.
How can I show TPoints and also display every horizontal bar?

Code: Select all

var
HSeries : array of THorizBarSeries;
PSeries : array of TPointSeries;

Code: Select all

procedure TForm4.Button1Click(Sender: TObject);
var
Rnd : Integer;
i : Integer;
j : Integer;
MyColour : TColor;
begin
SetLength(HSeries, 0);
SetLength(PSeries, 0);
Chart1.RemoveAllSeries;
Chart1.LeftAxis.Items.Clear;
series1.StackGroup := 0;
Chart1.LeftAxis.Items.Clear;
Chart1.LeftAxis.Items.Count := 0;
Chart1.Pages.MaxPointsPerPage := 16; 
for i := 0 to 150 do
  begin
  SetLength(HSeries, i+1);
  SetLength(PSeries, i+1);
  HSeries[i] := THorizBarSeries.Create(Chart1); 
  Hseries[i].MultiBar := mbNone;
  HSeries[i].StackGroup := i;
  HSeries[i].Marks.Visible := False;
  HSeries[i].BarWidthPercent := 90;//100; //95;
  Chart1.AddSeries(HSeries[i]);
  MyColour := clGreen;
  Rnd := Random(45);
  Rnd := 45 + Rnd;
  HSeries[i].AddX(Rnd, '', MyColour);
  Hseries[i].MultiBar := mbSelfStack;
  Chart1.LeftAxis.Items.Add(i);  {i+1}
  Chart1.LeftAxis.Items.Item[i].Text:= IntToStr(i+1)+' Chk'+IntToStr(Rnd); 
  {draw the yellow and red}
  for j := 2 to 3 do
    begin
    if j = 2 then myColour := clYellow
    else MyColour := clRed;
    HSeries[i].AddX(j*2, '', MyColour);
    end;

  {draw the point over the top of the horizontal bar graph}
  Rnd := Random(25);
  Rnd := 20 + Rnd;
  PSeries[i] := TPointSeries.Create(Chart1); // (self);
  PSeries[i].Marks.Visible := False;
  PSeries[i].Pointer.Style := psTriangle;
  PSeries[i].AddXY(Rnd, i, '', clYellow);
  Chart1.AddSeries(PSeries[i]);

  end; {for i}

end;
Attachments
2018-10-09_21-53-24.jpg
HorizBar series shows every bar when not adding the TPoint
2018-10-09_21-53-24.jpg (104.33 KiB) Viewed 10069 times
2018-10-09_21-54-31.jpg
Drawing the HorizBarSeries with adding a TPoint only draws every 2nd bar which is incorrect
2018-10-09_21-54-31.jpg (102.53 KiB) Viewed 10069 times

VideoTrack
Newbie
Newbie
Posts: 17
Joined: Thu Jan 04, 2018 12:00 am

Re: How to place a 'point' on a horizontal bar graph. [Solved]

Post by VideoTrack » Fri Oct 12, 2018 12:09 am

Resolved by adding the Point series separately:

Code: Select all

{______________________________________________________________________________}

procedure TForm4.Button1Click(Sender: TObject);
var
Rnd : Integer;
i : Integer;
j : Integer;
MyColour : TColor;
begin
{attempt to add a data set to the bar chart}

SetLength(HSeries, 0);
Chart1.RemoveAllSeries;
Chart1.LeftAxis.Items.Clear;
series1.StackGroup := 0;
Chart1.LeftAxis.Items.Clear;
Chart1.LeftAxis.Items.Count := 0;
Chart1.Pages.MaxPointsPerPage := 16; 
SetLength(HSeries, 150);
for i := 0 to 150 do
  begin
  HSeries[i] := THorizBarSeries.Create(Chart1); 
  Hseries[i].MultiBar := mbNone;
  HSeries[i].StackGroup := i;
  HSeries[i].Marks.Visible := False;
  HSeries[i].BarWidthPercent := 90;
  Chart1.AddSeries(HSeries[i]);
  MyColour := clGreen;
  Rnd := Random(45);
  Rnd := 45 + Rnd;
  HSeries[i].AddX(Rnd, '', MyColour);
  Hseries[i].MultiBar := mbSelfStack;
  Chart1.LeftAxis.Items.Add(i);
  Chart1.LeftAxis.Items.Item[i].Text:= IntToStr(151-i)+' GT:'+IntToStr(Rnd);

  {draw the yellow and red}
  for j := 2 to 3 do
    begin
    if j = 2 then myColour := clYellow
    else MyColour := clRed;
    HSeries[i].AddX(j*2, '', MyColour);
    end;

  end; {for i}
ScrllBarChange(Chart1);
end;
{______________________________________________________________________________}

procedure TForm4.Button2Click(Sender: TObject);
var
Rnd : Integer;
i : Integer;
begin
SetLength(PSeries, 150);
for i := 0 to 150 do
  begin
  {draw the point over the top of the horizontal bar graph}
  Rnd := Random(25);
  Rnd := 20 + Rnd;
  PSeries[i] := TPointSeries.Create(Chart1); 
  PSeries[i].Marks.Visible := False;
  PSeries[i].Pointer.Style := psTriangle;
  PSeries[i].Pointer.Size := 3;
  PSeries[i].AddXY(Rnd, i, '', clYellow);
  Chart1.AddSeries(PSeries[i]);
  end;
end;
{______________________________________________________________________________}
Attachments
2018-10-12_11-07-01.jpg
Add the Point series separately, not in the same loop that adds Horizontal Bar series.
2018-10-12_11-07-01.jpg (114.07 KiB) Viewed 10036 times

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

Re: How to place a 'point' on a horizontal bar graph.

Post by Yeray » Mon Oct 15, 2018 6:48 am

I'm glad to hear you found how to solve it!
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