Hints Over the Line
How can I display the X and Y point's values and text label moving mouse through the Line chart and chart Legend ?
Download
ActiveX Visual Basic 6 example source code
Download
Borland Delphi example source code
ActiveX Code :
Dim OnSeriesPoint As
Boolean
Dim OnLegendPoint As Boolean
Private Sub Form_Load()
With TChart1
.Aspect.View3D = False
.AddSeries scLine
.Series(0).FillSampleValues 10
.Axis.Bottom.Labels.DateTimeFormat = "dd/mm/yy hh:mm:ss"
End With
End Sub
Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As
Long, ByVal Y As Long)
Dim tmpL, tmpL2, ClickedValue As Integer
ClickedValue = -1
tmpL = -1
tmpL2 = 1000
With TChart1
If .Series(0).Clicked(X, Y) <> -1 And Not OnSeriesPoint Then
.Canvas.Brush.Style = bsSolid
.Canvas.Pen.Color = vbBlack
.Canvas.Brush.Color = vbWhite
.Canvas.TextOut X + 10, Y,
TChart1.Axis.Bottom.Labels.FormattedValue(.Series(0).XScreenToValue(X)) _
& ", " &
Str$(TChart1.Axis.Left.Labels.FormattedValue(.Series(0).YScreenToValue(Y)))
OnSeriesPoint = True
ClickedValue = .Series(0).Clicked(X,
Y)
End If
'Repaint Chart to clear Textoutputted Mark
If ClickedValue = -1 And OnSeriesPoint Then
OnSeriesPoint = False
.Repaint
End If
tmpL = TChart1.Legend.Clicked(X, Y)
If tmpL <> -1 And ((tmpL <> tmpL2) Or (Not OnLegendPoint))
Then
.Repaint
.Canvas.Brush.Color =
.Series(0).LegendItemColor(tmpL)
.Canvas.Rectangle X, Y, X + 20, Y +
20
.Canvas.Brush.Color = vbWhite
.Canvas.TextOut X + 20, Y + 7,
Str$(.Series(0).YValues.Value(.Series(0).LegendToValueIndex(tmpL))) & " "
tmpL2 = tmpL
OnLegendPoint = True
End If
If tmpL = -1 And OnLegendPoint Then
OnLegendPoint = False
.Repaint
End If
End With
End Sub
VCL Code :
unit UHintsOverLine;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TLineSeries;
procedure FormCreate(Sender: TObject);
procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
OnSeriesPoint : Boolean;
OnLegendPoint : Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(10);
Chart1.View3D := False;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var tmpL,tmpL2,ClickedValue : Integer;
begin
clickedvalue := -1;
tmpL2:= -1;
With Chart1 do
begin
If (Series1.Clicked(X, Y) <> -1) And
(not OnSeriesPoint) Then
begin
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Color := clBlack;
Canvas.Brush.Color := clWhite;
Canvas.TextOut(x+10,y,FormatFloat('#.00',Series1.XScreenToValue(x))+','+FormatFloat('#.00',Series1.YScreenToValue(y)));
OnSeriesPoint
:= True;
ClickedValue:= Series1.Clicked(x,y);
End;
//Repaint Chart to clear Textoutputted Mark
If (ClickedValue=-1) And
(OnSeriesPoint) Then
begin
OnSeriesPoint
:= False;
invalidate;
End;
tmpL := Chart1.Legend.Clicked(X, Y);
If (tmpL <> -1) And ((tmpL <> tmpL2) Or (not OnLegendPoint)) Then
begin
repaint;
Canvas.Brush.Color := Series1.LegendItemColor(tmpL);
Canvas.Rectangle( X, Y, X + 20, Y + 20);
Canvas.Brush.Color := clWhite;
Canvas.TextOut(x+15,y+7,FormatFloat('#.00',Series1.XValues.Items[Series1.LegendToValueIndex(tmpl)]));
tmpL2 :=
tmpL;
OnLegendPoint
:= True;
End;
If (tmpL2 = -1) And (OnLegendPoint)
Then
begin
OnLegendPoint
:= False;
Invalidate;
End;
End;
End;
End.
Home | Products | Order | About us | Downloads | Support |
Copyright
information. E-MAIL info@steema.com.
Privacy
Policy All other brands and product names are trademarks or registered trademarks of their respective owners. |