Color Line with Marks Tips

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Krishna
Newbie
Newbie
Posts: 16
Joined: Mon Jun 12, 2006 12:00 am
Contact:

Color Line with Marks Tips

Post by Krishna » Thu Aug 03, 2006 5:39 am

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.

Pep
Site Admin
Site Admin
Posts: 3272
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Aug 03, 2006 9:26 am

Hi Krishna,

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.

SteveP
Advanced
Posts: 132
Joined: Sun Sep 07, 2003 4:00 am

Post by SteveP » Thu Aug 03, 2006 2:17 pm

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

Post Reply