Teechart7中取点的坐标值的问题 ( 积分: 100 )

  • 主题发起人 主题发起人 至尊王
  • 开始时间 开始时间
有三个Series 且工具关联Series!!
在 Fromoncreate中:
Chart1.SeriesList.FillSampleValues(100);
procedure TForm1.ChartTool1Change(Sender: TCursorTool;
x, y: Integer;
const XValue, YValue:do
uble;
Series: TChartSeries;
ValueIndex: Integer);
begin
Label1.Caption := FloatToStr(XValue);
Label2.Caption := FloatToStr(YValue);
Label3.Caption := FloatToStr(Series1.YValue[ValueIndex]);
Label4.Caption := FloatToStr(Series2.YValue[ValueIndex]);
Label5.Caption := FloatToStr(Series3.YValue[ValueIndex]);
end;
[red]XXX.YValue[ValueIndex], 得到的值永远是:2.12199579096577E-311[/red]
 
不会吧,这么简单的。在把你的工具删了,重新加一个试一试,怪了
 
Label1.Caption := FloatToStr(XValue);
Label2.Caption := FloatToStr(YValue);
这二个值对吗?
如果不对,工具有问题
 
偷偷的问一下各位老大,TCursorTool是什么东东啊?
 
在TeeChart中的一个Cursor(十字测量)的工具
移动鼠标可以显示曲线上的值
 
多次Test,还是一样!
 
我该哭了,你说怎么办?
 
在那里啊,我怎么找不到啊 teechart standard 4.04
 
Delphi自带的teechart中没有,要TeeChart pro5以上版本
 
SnapPoint 没选ValueIndex就一直是-1
如果只用平滑移动的话需要计算Y的位置
var
I : Integer;
Diff :do
uble;
P :do
uble;
NextX,NextY :do
uble;
CurrX,CurrY :do
uble;
CursorY :do
uble;
I := Sender.NearestPoint(cssVertical,Diff);
P := Series.GetHorizAxis.CalcIncrement;
CurrX := Series.XValue;
CurrY := Series.YValue;
if XValue>=CurrX then
NextY := Series.YValue[I+1]
else
NextY := Series.YValue[I-1];
CursorY := CurrY+((NextY-CurrY)*ABS((XValue-CurrX)/P));
Label3.Caption := FormatFloat('0.00',CursorY);
以上只是个人见解,不知有无更简单的方法。
 
只要解决问题!不管如何,可以给大家再加100分!
 
很奇怪?!
根本不是分的问题了,使用TCursorTool根本不需要其他代码,在OnChange事件中可以得到一切的。
procedure TForm1.ChartTool1Change(Sender: TCursorTool;
x, y: Integer;
const XValue, YValue:do
uble;
Series: TChartSeries;
ValueIndex: Integer);
这个事件中的值都可以返回的,只要把TCursorTool关联一个Series
 
to yostgxf:
为何我的不行!???
 
[:(]不知道,重新开个工程试一试?
我1分钟就可以做个例子,一点没问题
 
to yostgxf:
我试了无数遍![red]不行[/red]我的代码:
===============unit1.pas=============
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, TeeTools, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TFastLineSeries;
Series2: TFastLineSeries;
Series3: TFastLineSeries;
ChartTool1: TCursorTool;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure FormCreate(Sender: TObject);
procedure ChartTool1Change(Sender: TCursorTool;
x, y: Integer;
const XValue, YValue:do
uble;
Series: TChartSeries;
ValueIndex: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.SeriesList.FillSampleValues(100);
end;

procedure TForm1.ChartTool1Change(Sender: TCursorTool;
x, y: Integer;
const XValue, YValue:do
uble;
Series: TChartSeries;
ValueIndex: Integer);
begin
Label1.Caption := FloatToStr(XValue);
Label2.Caption := FloatToStr(YValue);
Label3.Caption := FloatToStr(Series1.YValue[ValueIndex]);
Label4.Caption := FloatToStr(Series2.YValue[ValueIndex]);
Label5.Caption := FloatToStr(Series3.YValue[ValueIndex]);
end;

end.

[blue]=============unit1.dfm=================
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 40
Width = 32
Height = 13
Caption = 'Label1'
end
object Label2: TLabel
Left = 8
Top = 64
Width = 32
Height = 13
Caption = 'Label2'
end
object Label3: TLabel
Left = 8
Top = 88
Width = 32
Height = 13
Caption = 'Label3'
end
object Label4: TLabel
Left = 8
Top = 112
Width = 32
Height = 13
Caption = 'Label4'
end
object Label5: TLabel
Left = 8
Top = 136
Width = 32
Height = 13
Caption = 'Label5'
end
object Chart1: TChart
Left = 128
Top = 32
Width = 553
Height = 345
Title.Text.Strings = (
'TChart')
View3D = False
TabOrder = 0
object Series1: TFastLineSeries
Marks.Callout.Brush.Color = clBlack
Marks.Visible = False
LinePen.Color = clRed
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Y'
YValues.Order = loNone
end
object Series2: TFastLineSeries
Marks.Callout.Brush.Color = clBlack
Marks.Visible = False
LinePen.Color = clGreen
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Y'
YValues.Order = loNone
end
object Series3: TFastLineSeries
Marks.Callout.Brush.Color = clBlack
Marks.Visible = False
LinePen.Color = clYellow
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Y'
YValues.Order = loNone
end
object ChartTool1: TCursorTool
FollowMouse = True
Series = Series1
OnChange = ChartTool1Change
end
end
end[/blue]
除非把:snap:=true !
但snap:=true后移动非常奇怪!
[red]急需等答案!!!!!![/red]
 
每人吗?
 
[red]以上的方法都不对![/red]
解决办法:
procedure TForm1.FormCreate(Sender: TObject);
begin

Series1.FillSampleValues(100);
Series1.HorizAxis := aBothHorizAxis;
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-1do

begin

If Chart1.Series.Count >
0 then
begin

For i := Chart1.Axes.Top.PosAxis To Chart1.Axes.Bottom.PosAxisdo
begin

If Chart1.Series.Clicked(X, i) <>
-1 then
posi := i;
end;

Chart1.Canvas.TextOut( 10, 10 + (10 * s), 'Series ' + inttostr(s) + ' Value: ' + floattostr(Chart1.Series.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);
end;

end.

请给分吧!
 
to 那一刀:
[red]你的办法可以,我试了![/red]
谢谢各位!
特别是:yostgxf,alextsui,app2001,fei_l,likekoko,realLearning,w-s-y,迷糊
 
多人接受答案了。
 
后退
顶部