Page 1 of 1
Event line in a TBarSeries
Posted: Tue Jul 08, 2008 12:47 am
by 10546565
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:
(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]
Posted: Tue Jul 08, 2008 8:16 am
by yeray
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;
Posted: Tue Jul 08, 2008 4:48 pm
by 10546565
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)?
Posted: Wed Jul 09, 2008 7:53 am
by yeray
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);