📄 chart3unit.pas
字号:
unit Chart3Unit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, OWC_TLB, StdCtrls, ExtCtrls, MSDATASRC_TLB;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
ChartSpace1: TChartSpace;
Spreadsheet1: TSpreadsheet;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
Sheet : WorkSheet; // Spreadsheet
Chart : WCChart; // Chart
begin
//
// Fill the spreadsheet with some data
//
Sheet := Spreadsheet1.ActiveSheet;
With Sheet do
Begin
Range['A1', 'A10'].Set_Formula('=Row()');
Range['B1', 'B10'].Set_Formula('=A1^2');
Range['A12','A12'].Set_Formula('=Max(A1:A10)');
Range['B12','B12'].Set_Formula('=Max(B1:B10)');
End;
// Create new Chart
With ChartSpace1 do
Begin
Clear;
Refresh;
// Specify the datasource
{!!}
DataSource := Sheet.Parent AS MSDATASRC_TLB.DataSource;
{!!}
// Add new Chart
Chart := Charts.Add(0);
// Set the type of Chart - Scattered Smooth Line Markers
Chart.Type_ := chChartTypeScatterSmoothLineMarkers;
// Specify data for X
Chart.SetData(chDimXValues, 0, 'A1:A10');
// ... and Y values as a range of cells
Chart.SetData(chDimYValues, 0, 'B1:B10');
End;
With Chart do
Begin
//
// Shows titles for the axes
//
With Axes[chAxisPositionBottom] do
Begin
HasTitle := True;
Title.Caption := 'X';
Title.Font.Set_Size(8);
MajorUnit := 1;
End;
With Axes[chAxisPositionLeft] do
Begin
HasTitle := True;
Title.Caption := 'X Squared';
Title.Font.Set_Size(8);
MajorUnit := 10;
End;
// Specify the maximum and minimum values for axes
Scalings[chDimXValues].Maximum := Sheet.Range['A12', 'A12'].Value;
Scalings[chDimXValues].Minimum := 1;
Scalings[chDimYValues].Maximum := Sheet.Range['B12', 'B12'].Value;
// Set additional styles
With SeriesCollection.Item[0] do
Begin
Marker.Style := chMarkerStyleDot;
Marker.Size := 6;
Line.Set_Weight(1);
End
End;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -