📄 chartunit.pas
字号:
unit ChartUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, OWC_TLB, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
ChartSpace1: TChartSpace;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
Chart : WCChart; // Chart
Series : WCSeries; // Serie
XValues : Variant; // X-axis values
begin
//
// Clear the current chart
//
ChartSpace1.Clear;
ChartSpace1.Refresh;
//
// Let's create a new chart
//
Chart := ChartSpace1.Charts.Add(0);
//
// Let's add the title for the chart
//
Chart.HasTitle := True;
Chart.Title.Caption := 'Sales By Category';
//
// Data for X-axis
//
XValues := VarArrayCreate([0,7], varVariant);
XValues[0] := 'Beverages'; XValues[1] := 'Condiments';
XValues[2] := 'Confections'; XValues[3] := 'Dairy Products';
XValues[4] := 'Grains & Cereals'; XValues[5] := 'Meat & Poultry';
XValues[6] := 'Produce'; XValues[7] := 'Seafood';
//
// Add the new Series object
//
Series := Chart.SeriesCollection.Add(0);
With Series do
Begin
// Set Series caption
Caption := '1998';
// and data
SetData(chDimCategories,chDataLiteral, XValues);
// Y-axes data will be taken from the dynamic variant array
SetData(chDimValues, chDataLiteral,
VarArrayOf(
[104737, 50952, 78128, 117797,52902, 80160, 47491, 62435]
));
// Set the Chart type - Clustered Column
Type_ := chChartTypeColumnClustered;
End;
//
// Add the new Series object
//
Series := Chart.SeriesCollection.Add(1);
With Series do
Begin
// Set Series caption
Caption := '1999';
// and data
SetData(chDimCategories, chDataLiteral, XValues);
// Y-axes data will be taken from the dynamic variant array
SetData(chDimValues, chDataLiteral,
VarArrayOf (
[20000, 15000, 36000, 56000, 40000, 18000, 20000, 33000]
));
// Set the Chart type - Line Markers
Type_ := chChartTypeLineMarkers;
End;
//
// Add an axis
//
Chart.Axes.Add(Chart.Axes[chAxisPositionLeft].Scaling,
chAxisPositionRight, chValueAxis);
//
// Set some of its properties
//
Chart.Axes[chAxisPositionLeft ].NumberFormat := '$#,##0';
Chart.Axes[chAxisPositionRight].NumberFormat := '0';
Chart.Axes[chAxisPositionLeft ].MajorUnit := 20000;
Chart.Axes[chAxisPositionRight].MajorUnit := 20000;
//
// Add a legend at the bottom part of our chart
//
Chart.HasLegend := True;
Chart.Legend.Position := chLegendPositionBottom;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -