Hi,
I have placed a color line to identify exact position of the datapoint to the X-axis.
I need to popup the Mark Tip of the datapoint if the line position matches the datapoint when I am dragging the color line along the graph drawn.
Regards,
Krishna.
Color Line with Marks Tips
Hi Krishna,
find one example below whic does this using :
find one example below whic does this using :
Code: Select all
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TLineSeries;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Chart1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
XVal : integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(100);
Series1.HorizAxis := aBothHorizAxis;
Chart1.TabStop := true;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var i, s, posi : integer;
begin;
Chart1.Repaint;
Chart1.Canvas.Brush.Style := bsClear;
If Chart1.SeriesCount > 0 Then
begin
for s := 0 to Chart1.SeriesCount-1 do
begin
If Chart1.Series[s].Count > 0 Then begin
For i := Chart1.Axes.Top.PosAxis To Chart1.Axes.Bottom.PosAxis do begin
If Chart1.Series[s].Clicked(X, i) <> -1 Then posi := i;
end;
Chart1.Canvas.TextOut( 10, 10 + (10 * s), 'Series ' + inttostr(s) + ' Value: ' + floattostr(Chart1.Series[s].YScreenToValue(posi)));
end;
end;
end;
Chart1.Canvas.Pen.Color := clBlue;
Chart1.Canvas.MoveTo (X, Chart1.Axes.Top.PosAxis);
Chart1.Canvas.LineTo( X, Chart1.Axes.Bottom.PosAxis);
XVal := X;
end;
procedure TForm1.Chart1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var i, s, posi : integer;
begin
' you must check the key here ..( if key = ...)
' and depending of key increase or decrease the XVal
XVal := Xval+1;
Chart1.Repaint;
Chart1.Canvas.Brush.Style := bsClear;
If Chart1.SeriesCount > 0 Then
begin
for s := 0 to Chart1.SeriesCount-1 do
begin
If Chart1.Series[s].Count > 0 Then begin
For i := Chart1.Axes.Top.PosAxis To Chart1.Axes.Bottom.PosAxis do begin
If Chart1.Series[s].Clicked(Xval, i) <> -1 Then posi := i;
end;
Chart1.Canvas.TextOut( 10, 10 + (10 * s), 'Series ' + inttostr(s) + ' Value: ' + floattostr(Chart1.Series[s].YScreenToValue(posi)));
end;
end;
end;
Chart1.Canvas.Pen.Color := clBlue;
Chart1.Canvas.MoveTo (XVal, Chart1.Axes.Top.PosAxis);
Chart1.Canvas.LineTo( XVal, Chart1.Axes.Bottom.PosAxis);
end;
end.
Pep Jorge
http://support.steema.com
http://support.steema.com
Perhaps use a CursorTool with Snap = false and respond to its OnChange event. Note that with Snap=false, the OnChange event's ValueIndex will = -1. Maybe use another hidden CursorTool with Snap = true and check if the two CursorTools XValues are the same. However, the CursorTool with Snap=false has its XValue as a double and might not become set equal to the XValue of the other CursorTool that has Snap=true, even though on the chart the two CursorTools can be seen to overlap each other. The color of the CursorTools will change when they overlap.
Steve
Steve