Page 1 of 1

DragMarks tool

Posted: Tue Nov 14, 2017 4:08 am
by 16579481
If I have several point series on my chart. By making the DragMarksTool active I can just drag the marks for the points in the last series. How do I make the marks for all of the series drag-able? The number of series depends on the data so it has to be done at run time.

Thanks again,

Jim

Re: DragMarks tool

Posted: Tue Nov 14, 2017 7:31 am
by yeray
Hello Jim,

Assigning nil to the TDragMarksTool's Series property should enable it for all the series.
An alternative is to set the TDragMarksTool's Series at OnMouseMove. Ie:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var SeriesIndex: Integer;
begin
  for SeriesIndex:=0 to Chart1.SeriesCount-1 do
  begin
    if Chart1[SeriesIndex].Marks.Clicked(X, Y) > -1 then
       (Chart1.Tools[0] as TDragMarksTool).Series:=Chart1[SeriesIndex];
  end;
end;

Re: DragMarks tool

Posted: Tue Nov 14, 2017 4:59 pm
by 16579481
Thanks - that first solution of setting the series property to nil is simple and it works. I would not have guessed that. What is the procedure to restore it to normal?

Re: DragMarks tool

Posted: Wed Nov 15, 2017 7:28 am
by yeray
Hello,
JimR wrote:Thanks - that first solution of setting the series property to nil is simple and it works. I would not have guessed that.
I'm glad to hear it works as you wish now.
JimR wrote:What is the procedure to restore it to normal?
By "normal" do you mean what you said in the opening post here?
JimR wrote:I can just drag the marks for the points in the last series
This is not the behaviour I observe by default. The TDragMarksTool works with all the series for me by default:

Code: Select all

uses Series, TeeTools;

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

  for i:=0 to 3 do
    with Chart1.AddSeries(TPointSeries) do
    begin
      Marks.Visible:=True;
      FillSampleValues(5);
    end;

  Chart1.Tools.Add(TDragMarksTool);
end;
What version are you using?

Re: DragMarks tool

Posted: Wed Nov 15, 2017 12:12 pm
by 16579481
I meant your first example"
"Assigning nil to the TDragMarksTool's Series property should enable it for all the series."

How does one undo that ?

Re: DragMarks tool

Posted: Wed Nov 15, 2017 1:30 pm
by yeray
Hello,
JimR wrote:I meant your first example"
"Assigning nil to the TDragMarksTool's Series property should enable it for all the series."

How does one undo that ?
By default, Series is nil (1). You can check it with this example:

Code: Select all

uses Series, TeeTools;

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

  for i:=0 to 3 do
    with Chart1.AddSeries(TPointSeries) do
    begin
      Marks.Visible:=True;
      FillSampleValues(5);
    end;

  Chart1.Tools.Add(TDragMarksTool);

  if (Chart1.Tools[0] as TDragMarksTool).Series = nil then
     Caption:='Series is nil'
  else
     Caption:='Series is assigned';
end;
If at some stage you assigned a Series to the TDragMarksTool to limit it (2), and later you set it to nil to use it in all the Series again (3), and you want to remember to what Series did you assign it at the beginning to reassign it (4), you can store the Series you assigned when setting to nil (at point 3). Ie:

Code: Select all

var mySeries: TChartSeries;
//...
  mySeries:=(Chart1.Tools[0] as TDragMarksTool).Series;
  (Chart1.Tools[0] as TDragMarksTool).Series:=nil;
And then restore that series (at point 4):

Code: Select all

  (Chart1.Tools[0] as TDragMarksTool).Series:=mySeries;

Re: DragMarks tool

Posted: Wed Nov 15, 2017 7:21 pm
by 16579481
ok, that is clearer. Thanks again.