Page 1 of 1
Draggable Vertical Lines...
Posted: Fri Nov 25, 2005 12:59 pm
by 9337407
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
Posted: Fri Nov 25, 2005 1:08 pm
by narcis
Hi Maxc72,
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;
For more information on TChart tools features please have a look at TeeChart features demo available at its program group.
Posted: Fri Nov 25, 2005 5:37 pm
by 9337407
Hi thank's for your help, i've tried it and it works fine, but i need that the line height is adjustable and not fixed to the graph panel. i need that the line heigth is about half of the graph panel height..
Posted: Mon Nov 28, 2005 10:11 am
by narcis
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;
Posted: Mon Nov 28, 2005 12:00 pm
by 9337407
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:
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;
Posted: Tue Nov 29, 2005 4:58 pm
by narcis
Hi Maxc72,
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.
Ok, then you can calculate it from TChart's rectangle (ChartRect property). Using the code below may work better for what you request.
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;
There is another problem, when i try to set dragging at runtime it have no effect, this code don't work at runtime:
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.
Posted: Wed Nov 30, 2005 12:50 pm
by 9337407
Hi, I'm sorry for bother you but i i've tried your code, and i think there was some misunderstanding, i must repruduce a graph like this:
and i must drag (left and rigth) the yellow vertical lines.
Regards,
Massimiliano
Posted: Thu Dec 01, 2005 4:27 pm
by Pep
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 :
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;
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 :
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;