Recent

Author Topic: Adding Labels to points.  (Read 2098 times)

chucky

  • New Member
  • *
  • Posts: 19
Adding Labels to points.
« on: May 31, 2013, 07:21:26 am »
The Tutorial at

http://wiki.freepascal.org/TAChart_Tutorial:_Chart_Tools

procedure TForm1.ChartToolset1DataPointClickTool1PointClick(
  ATool: TChartTool; APoint: TPoint);
var
  x, y: Double;
begin
  with ATool as TDatapointClickTool do
    if (Series <> nil) then
      with (Series as TLineSeries) do begin
        x := GetXValue(PointIndex);
        y := GetYValue(PointIndex);
        { --- next line removed --- }
//        Statusbar1.SimpleText := Format('%s: x = %f, y = %f', [Title, x, y]);
        { --- next line added --- }
        ListSource.SetText(PointIndex, Format('x = %f'#13#10'y = %f', [x,y]));
      end;
end

does not compile under 1.0.8

There is no ListSource.SetText(). Was this tutorial written with an older version of the chart package or is this something added since the release of 1.0.8?

Using the 1.0.8 release is their a way of setting the text of a point after it has been added?


wp

  • Hero Member
  • *****
  • Posts: 6319
Re: Adding Labels to points.
« Reply #1 on: May 31, 2013, 12:44:45 pm »
I tried to write the tutorials from the release version which was about 1.0 at this time. When using new features there should be a hint in the text.

In your case, obviously a later version, probably the trunk version, was used because the SetText method of the ListSource is a recent addition. However, the functionality has already been there even in the older versions since this method is just a short-cut for writing
Code: [Select]
  ListSource.Item[PointIndex]^.Text := 'some text';

[EDIT] You have to repaint the chart afterwards to show the changes immediately.

I'll modify the tutorial such that it compiles under older Lazarus versions (but proably not under 0.xx).
« Last Edit: May 31, 2013, 01:14:22 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

chucky

  • New Member
  • *
  • Posts: 19
Re: Adding Labels to points.
« Reply #2 on: June 02, 2013, 06:30:43 am »
Thanks!!

 ListSource.Item[PointIndex]^.Text := 'some text'

is what I needed.