关于tchart(100分)

  • 主题发起人 主题发起人 ugvanxk
  • 开始时间 开始时间
U

ugvanxk

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在tchart的x轴的坐标为0-4,然后在1-4的坐标上写上a,b,c,d
y轴也0-4,然后1-4坐标上写上a,b,c,d
 
用addx()
addy()
 
我用addxy加上了x轴,y轴怎么也不显示lable
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, ExtDlgs;

type
TForm1 = class(TForm)
Chart1: TChart;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses Series; //必须要加上去
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
Series1: TBarSeries;
begin
Series1 := TBarSeries.Create(Chart1);
Series1.ParentChart := Chart1;
Series1.Marks.Style := smsPercent;
Chart1.LeftAxis.Maximum := 50;
Chart1.LeftAxis.Minimum := 0;
Chart1.LeftAxis.Increment := 5;
chart1.AddSeries(Series1);
series1.Clear;
for i := 0 to 5 do
begin
Series1.Add(20 + 5 * i, '嘉宾' + inttostr(i), clRed);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
I: Integer;
Series1: TBarSeries;
begin
Series1 := TBarSeries.Create(Chart1);
Series1.ParentChart := Chart1;
Series1.Marks.Style := smsPercent;
with Series1 do
begin
clear;
for I := 0 to 100 do
AddXY(I, Sin(I / 8), inttostr(i), clyellow);
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
Series2, Series1: TBarSeries;
begin
Series1 := TBarSeries.Create(Chart1);
Series1.ParentChart := Chart1;
Series2 := TBarSeries.Create(Chart1);
Series2.ParentChart := Chart1;
Series1.Marks.Style := smsValue;
Series1.CustomBarWidth := 10;
Chart1.View3D := false;
Series1.AddBar(11, '0.1', clred);
Series1.AddBar(33, '0.2', clred);
Series1.AddBar(12, '0.3', clred);
Series1.AddBar(12, '0.4', clred);
Series1.AddBar(22, '0.5', clred);
Series1.AddBar(10, '0.6', clred);

Series2.AddXY(0, 11, '', clgreen);
Series2.AddXY(1, 33, '', clgreen);
Series2.AddXY(2, 12, '', clgreen);
Series2.AddXY(3, 12, '', clgreen);
Series2.AddXY(4, 22, '', clgreen);
Series2.AddXY(5, 10, '', clgreen);
end;
end.
 
主要是y轴显示为lable
 
利用GetAxisLabel属性,如果ValueIndex=-1,则表示x轴,然后根据StrToInt(LabelText)进行填写
y轴的,就是ValueIndex,然后给LabelText赋值就可以了。
手头目前没有实例,有空给你email一个。[:)]

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin

end;
 
yzhishi
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Series1.AddXY(1, 1, 'a');
Series1.AddXY(2, 2, 'b');
Series1.AddXY(3, 3, 'c');
Series1.AddXY(4, 4, 'd');
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
if ValueIndex = -1 then
try
case Trunc(StrToFloat(LabelText)) of
0: LabelText := '-';
1: LabelText := 'a';
2: LabelText := 'b';
3: LabelText := 'c';
4: LabelText := 'd';
end;
except
end;
end;
 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
回复
0
查看
825
不得闲
回复
0
查看
695
万一
回复
0
查看
835
不得闲
后退
顶部