Draggable Vertical Lines...
Draggable Vertical Lines...
I must create horizontal-draggable vertical lines over a graph, moreover i must know what value them have over a serie..
Somebody could help me?
Reagards
Somebody could help me?
Reagards
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Maxc72,
I'd suggest you to use a TColorLineTool and implement something like the code below on its DragLine event.
For more information on TChart tools features please have a look at TeeChart features demo available at its program group.
I'd suggest you to use a TColorLineTool and implement something like the code below on its DragLine event.
Code: Select all
procedure TForm1.ChartTool1DragLine(Sender: TColorLineTool);
begin
Chart1.Title.Text[0]:=FloatToStr(Sender.Value);
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Maxc72,
Then you can use a TColorBandTool and do something like:
Then you can use a TColorBandTool and do something like:
Code: Select all
var
Form1: TForm1;
StartVal, MidVal, EndVal: Double;
ToolHeight: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues();
ToolHeight:=Chart1.Height div 2;
MidVal:=(Series1.MaxYValue-Series1.MinYValue)/2;
With ChartTool1 do
begin
StartValue:=MidVal - (ToolHeight div 2);
EndValue:=MidVal + (ToolHeight div 2);
StartLine.AllowDrag:=True;
EndLine.AllowDrag:=True;
StartVal:=StartValue;
EndVal:=EndValue;
end;
Chart1.Title.Text[0]:=FloatToStr(MidVal);
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
if ChartTool1.StartValue <> StartVal then
begin
ChartTool1.EndValue:=ChartTool1.StartValue+ToolHeight;
StartVal:=ChartTool1.StartValue
end
else
if ChartTool1.EndValue <> EndVal then
begin
ChartTool1.StartValue:=ChartTool1.EndValue-ToolHeight;
EndVal:=ChartTool1.EndValue;
end;
MidVal:=StartVal+(ToolHeight/2);
Chart1.Title.Text[0]:=FloatToStr(MidVal);
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Hi I've tried to use the code but i obtain a very wide band, I've reduced the wide of the band but the heigth is still equal to graph panel and if i vertical scroll the graph the band is still here.
There is another problem, when i try to set dragging at runtime it have no effect, this code don't work at runtime:
if i create the tool in the ide and i set the dragging properties to true it work's fine and i can turn it on and off at runtime, but if i create the bar at runtime i can't set this properties (i.e. i can set them but there is no effect)
There is another problem, when i try to set dragging at runtime it have no effect, this code don't work at runtime:
Code: Select all
ChartTool1.StartLine.AllowDrag:=True;
ChartTool1.EndLine.AllowDrag:=True;
if i create the tool in the ide and i set the dragging properties to true it work's fine and i can turn it on and off at runtime, but if i create the bar at runtime i can't set this properties (i.e. i can set them but there is no effect)
narcis wrote:Hi Maxc72,
Then you can use a TColorBandTool and do something like:
Code: Select all
var Form1: TForm1; StartVal, MidVal, EndVal: Double; ToolHeight: Integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Series1.FillSampleValues(); ToolHeight:=Chart1.Height div 2; MidVal:=(Series1.MaxYValue-Series1.MinYValue)/2; With ChartTool1 do begin StartValue:=MidVal - (ToolHeight div 2); EndValue:=MidVal + (ToolHeight div 2); StartLine.AllowDrag:=True; EndLine.AllowDrag:=True; StartVal:=StartValue; EndVal:=EndValue; end; Chart1.Title.Text[0]:=FloatToStr(MidVal); end; procedure TForm1.Chart1AfterDraw(Sender: TObject); begin if ChartTool1.StartValue <> StartVal then begin ChartTool1.EndValue:=ChartTool1.StartValue+ToolHeight; StartVal:=ChartTool1.StartValue end else if ChartTool1.EndValue <> EndVal then begin ChartTool1.StartValue:=ChartTool1.EndValue-ToolHeight; EndVal:=ChartTool1.EndValue; end; MidVal:=StartVal+(ToolHeight/2); Chart1.Title.Text[0]:=FloatToStr(MidVal); end;
Code: Select all
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Maxc72,
Ok, then you can calculate it from TChart's rectangle (ChartRect property). Using the code below may work better for what you request.Hi I've tried to use the code but i obtain a very wide band, I've reduced the wide of the band but the heigth is still equal to graph panel and if i vertical scroll the graph the band is still here.
Code: Select all
var
Form1: TForm1;
StartVal, MidVal, EndVal: Double;
ToolHeight: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues();
MidVal:=Series1.MinYValue+(Series1.MaxYValue-Series1.MinYValue)/2;
With ChartTool1 do
begin
Axis:=Chart1.Axes.Left;
StartLine.AllowDrag:=True;
EndLine.AllowDrag:=True;
StartValue:=Series1.MinYValue;
EndValue:=MidVal;
StartVal:=StartValue;
EndVal:=EndValue;
end;
Chart1.Title.Text[0]:=FloatToStr(StartVal+((EndVal-StartVal)/2));
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
ToolHeight:=(Chart1.ChartRect.Bottom-Chart1.ChartRect.Top) div 2;
if ChartTool1.StartValue <> StartVal then
begin
ChartTool1.EndValue:=ChartTool1.StartValue+ToolHeight;
StartVal:=ChartTool1.StartValue
end
else
if ChartTool1.EndValue <> EndVal then
begin
ChartTool1.StartValue:=ChartTool1.EndValue-ToolHeight;
EndVal:=ChartTool1.EndValue;
end;
MidVal:=StartVal+(ToolHeight/2);
Chart1.Title.Text[0]:=FloatToStr(MidVal);
end;
Yes, this is a problem I've been able to reproduce. I've added it to our defect list (TV52011105) to be fixed for future releases.There is another problem, when i try to set dragging at runtime it have no effect, this code don't work at runtime:
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Hi Massimiliano,
one way to do this could be using the ClipRectangle method, in conjunction with TCursor Tools, this method will restric the Rect to display the Cursor. An example could be :
Another way to do this (which solves the fickering) could be a trick. It's to use a fake Series, adding the same data as the first Series, and creating a custom vertical axis for this Serie, setting the Start position to desired position you want that end the Cursor line. Then you only will have to asign the Cursor Tool to the fake series and hide the Axis and Series, you could use similar code like the following :
one way to do this could be using the ClipRectangle method, in conjunction with TCursor Tools, this method will restric the Rect to display the Cursor. An example could be :
Code: Select all
procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
Function SeriesRect(Series:TChartSeries):TRect;
begin
With result do
begin
Left:=Series.GetHorizAxis.IStartPos;
Right:=Series.GetHorizAxis.IEndPos;
Top:=Series.GetVertAxis.IStartPos+100;
Bottom:=Series.GetVertAxis.IEndPos-100;
end;
end;
begin
With Chart1 do
if CanClip then
Canvas.ClipRectangle(SeriesRect( Sender as TChartSeries ));
end;
procedure TForm1.ChartTool2Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
Charttool2.Repaint;
end;
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
// Series
Series1.FillSampleValues(10);
Series2.FillSampleValues(10);
Series2.Color := clnone;
Series2.ShowInLegend:=false;
// Custom vertical axis
with Chart1.CustomAxes.Items[0] do
begin
StartPosition:=50;
Visible :=false;
Series2.CustomVertAxis:=Chart1.CustomAxes.Items[0];
end;
// Cursor Tool
ChartTool1.Series := Series2;
Charttool1.Style := cssVertical;
end;
Pep Jorge
http://support.steema.com
http://support.steema.com