Event line in a TBarSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Event line in a TBarSeries

Post by TestAlways » Tue Jul 08, 2008 12:47 am

I need to add an event line below a TBarSeries, showing events. The user can then see where events occur in the series.

Something like the red line with orange triangles shown in the image below:

Image

(I don't really want to overwrite the axis title--I just wanted to mock something up).

How would I accomplish something like this using TChart?

Thank you,
Ed Dressel[/img]

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

Post by Yeray » Tue Jul 08, 2008 8:16 am

Hi TestAlways,

I've achieved something really similar to your picture with the following code. In this example, Series1 is the BarSeries and Series2 is a LineSeries.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var max: double;
begin
  Chart1.View3D := False;

  Series1.FillSampleValues(15);

  Chart1.MarginBottom := 7;
  Chart1.Axes.Left.AutomaticMinimum := False;
  Chart1.ClipPoints := False;

  max := Series1.YValues.MaxValue;

  Series2.Pointer.Visible := True;
  Series2.Pointer.Size := 7;
  Series2.ShowInLegend := False;

  with Series2 do
  begin
    AddXY(0, -max/10);
    AddXY(7, -max/10);
    AddXY(9, -max/10);
    AddXY(10, -max/10);
    AddXY(14, -max/10);
  end;
end;

function TForm1.Series2GetPointerStyle(Sender: TChartSeries;
  ValueIndex: Integer): TSeriesPointerStyle;
begin
  if Sender = Series2 then
  begin
    if (ValueIndex = 0) or (ValueIndex = Series2.Count-1) then
      Result := psNothing
    else
      Result := psTriangle;
  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

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Post by TestAlways » Tue Jul 08, 2008 4:48 pm

Nice work! As far as I can tell (until implementation) it's going to be exactly what I need.

But one question, on a series click, how do I get the X index (not the X value)?

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

Post by Yeray » Wed Jul 09, 2008 7:53 am

Hi Ed,

As you can see in the method header, you have the ValueIndex.

Code: Select all

procedure Series1Click(Sender: TChartSeries; ValueIndex: Integer;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
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