Page 1 of 1

TColorLineTool range or movement

Posted: Sat May 15, 2010 2:31 am
by 16456147
I'm using TChart 2010 and I have a Chart with a single bar series and 4 TColorLineTools. Each line represents a threshold for the values in the series. Like High Fail, High Warn, Low Warn, Low Fail. I would like the user to be able to move the lines up and down to adjust the thresholds but I can't allow the High Fail Line to drop below the High Warn line. Likewise the High Warn line can't go above the High Fail line or fall below the Low Warn line. etc.

Is there some event or property I can set that will limit the range of movement of the line to a max/min value? I know about the NoLimitDrag property but I think that only limits to the min/max of the visible axis.

Thanks
Scott

Re: TColorLineTool range or movement

Posted: Mon May 17, 2010 8:45 am
by narcis
Hi Scott,

I'm not able to reproduce this here using code snippet below. Can you please modify it or attach a simple example project we can run "as-is" to reproduce the problem here?

Code: Select all

uses Series, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
var i,j: Integer;
    tmpColorLine: TColorLineTool;
begin
  Chart1.AddSeries(TBarSeries.Create(Self));

  for i:=0 to 100 do
    Chart1[0].Add(10*i);

  for j:=0 to 3 do
  begin
    tmpColorLine:=TColorLineTool.Create(Self);
    tmpColorLine.Axis:=Chart1.Axes.Left;
    tmpColorLine.Value:=100*(j+1);

    Chart1.Tools.Add(tmpColorLine);
  end;
end;
Thanks in advance.

Re: TColorLineTool range or movement

Posted: Mon May 17, 2010 6:35 pm
by 16456147
There is nothing wrong with your code. The problem is I need to be able to restrict the range of movement for each bar.

Your example creates a chart with 4 TColorLines at the 100, 200, 300, 400 values on the left axis. For the sake of discussion lets call those lines Line1, Line2, Line3, Line4 with those respective values. I need Line1 to have a range of movement that is restricted to the axis minimum (in this case 0) and the value of Line2 (in this case 200). Line2's movement should have a minimum value of Line1 and a max of Line3. Line3's movement should have a minimum value of Line2 and a max of Line4. Line4's movement should have a minimum value of Line3 and a max of the axis maximum. In other words a given line should not be able to be dragged above or below a line that is directly above it or below it. Obviously, as lines are moved that changes the range of movement of the line above and below it. For example: Line 2 is move to the value 150. Now Line 1 can only move between 0 and 150, but Line 3 can now move between 150 and 400.

Is there any way to do this?

Thanks
Scott

Re: TColorLineTool range or movement

Posted: Tue May 18, 2010 7:29 am
by narcis
Hi Scott,

Thanks for the explanation. Now I understand which is you requirement. Yes, this is possible using TColorLineTool's events, for example:

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeeComma, ExtCtrls, TeeProcs, TeEngine, Chart, TeeTools;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    TeeCommander1: TTeeCommander;
    procedure FormCreate(Sender: TObject);
    procedure ChartTool1DragLine(Sender: TColorLineTool);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i,j: Integer;
    tmpColorLine: TColorLineTool;
begin
  Chart1.AddSeries(TBarSeries.Create(Self));

  for i:=0 to 100 do
    Chart1[0].Add(10*i);

  for j:=0 to 3 do
  begin
    tmpColorLine:=TColorLineTool.Create(Self);
    tmpColorLine.Axis:=Chart1.Axes.Left;
    tmpColorLine.Value:=100*(j+1);
    tmpColorLine.OnDragLine:=ChartTool1DragLine;

    Chart1.Tools.Add(tmpColorLine);
  end;
end;

procedure TForm1.ChartTool1DragLine(Sender: TColorLineTool);
var Index: Integer;
    tmpColorLine1: TColorLineTool;
    MinValue,
    MaxValue: Double;
begin
  Index:=Chart1.Tools.IndexOf(Sender);

  tmpColorLine1:=(Sender as TColorLineTool);

  if Index>0 then
    MinValue:=(Chart1.Tools[Index-1] as TColorLineTool).Value
  else
    MinValue:=0;

  if Index<Chart1.Tools.Count-1 then
    MaxValue:=(Chart1.Tools[Index+1] as TColorLineTool).Value
  else
    MaxValue:=Chart1.Axes.Left.Maximum;

  if tmpColorLine1.Value<MinValue then
    tmpColorLine1.Value:=MinValue;

  if tmpColorLine1.Value>MaxValue then
    tmpColorLine1.Value:=MaxValue;
end;

end.

Re: TColorLineTool range or movement

Posted: Tue May 18, 2010 6:49 pm
by 16456147
Works perfectly!

Thanks!
Scott