答案 0 :(得分:1)
除了行数据TLineSeries
之外,添加TFastLineSeries
Stairs
属性设置为true
以创建标记指定数据点的虚线。 (结果图表的图像附在答案的末尾)。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, Series;
type
TForm1 = class(TForm)
Chart1: TChart;
LineSeries: TLineSeries;
StairSeries: TFastLineSeries;
procedure FormCreate(Sender: TObject);
procedure StairSeriesGetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);
private
BottomMinimum : double;
LeftMinimum : double;
DataPoint : double;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Fx(x : double) : double;
begin
Result := ((x - 1.5) * 20) + 17;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LineSeries.Clear;
StairSeries.Clear;
LeftMinimum := 12;
BottomMinimum := 1.25;
DataPoint := 1.68;
LineSeries.AddXY( 1.5, Fx(1.5) );
LineSeries.AddXY( 1.6, Fx(1.6) );
LineSeries.AddXY( 1.7, Fx(1.7) );
StairSeries.AddXY( BottomMinimum, Fx(DataPoint) );
StairSeries.AddXY( DataPoint, Fx(DataPoint) );
StairSeries.AddXY( DataPoint, LeftMinimum );
Chart1.LeftAxis.SetMinMax( LeftMinimum, LeftMinimum + 12 );
Chart1.BottomAxis.SetMinMax( BottomMinimum, BottomMinimum + 0.75 );
end;
procedure TForm1.StairSeriesGetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);
begin
if valueIndex = 0 then
MarkText := ' '+Format('%5.2n',[ Fx(DataPoint) ])
else if valueIndex = 1 then
MarkText := ''
else
MarkText := ' '+Format('%5.2n',[ DataPoint ])
end;
end.
DFM:
object Form1: TForm1
Left = 234
Top = 127
Width = 602
Height = 533
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Chart1: TChart
Left = 56
Top = 24
Width = 465
Height = 409
BackWall.Brush.Color = clWhite
BackWall.Brush.Style = bsClear
Title.Text.Strings = (
'TChart')
Legend.Visible = False
View3D = False
TabOrder = 0
object LineSeries: TLineSeries
Marks.ArrowLength = 8
Marks.Visible = False
SeriesColor = clBlue
LinePen.Color = clBlue
LinePen.Width = 4
Pointer.InflateMargins = True
Pointer.Style = psCircle
Pointer.Visible = True
XValues.DateTime = False
XValues.Name = 'X'
XValues.Multiplier = 1.000000000000000000
XValues.Order = loAscending
YValues.DateTime = False
YValues.Name = 'Y'
YValues.Multiplier = 1.000000000000000000
YValues.Order = loNone
end
object StairSeries: TFastLineSeries
Marks.ArrowLength = 8
Marks.Transparent = True
Marks.Frame.Visible = False
Marks.Visible = True
SeriesColor = clRed
OnGetMarkText = StairSeriesGetMarkText
LinePen.Color = clRed
LinePen.Style = psDash
LinePen.Width = 2
XValues.DateTime = False
XValues.Name = 'X'
XValues.Multiplier = 1.000000000000000000
XValues.Order = loAscending
YValues.DateTime = False
YValues.Name = 'Y'
YValues.Multiplier = 1.000000000000000000
YValues.Order = loNone
end
end
end
注意:这是我最初使用Delphi 10.2构建的Delphi 7示例,并使用Delphi 2007对其进行了测试。我将代码降级为Delphi 7.
要在Delphi 2007或更高版本中使用,请将设置Axes MinMax的代码更改为:
Chart1.Axes.Left.SetMinMax(LeftMinimum, LeftMinimum+12);
Chart1.Axes.Bottom.SetMinMax(BottomMinimum, BottomMinimum+0.75);
结果图表应如下所示: