Mega Code Archive

 
Categories / Delphi / Graphic
 

Radar Chart

Title: Radar Chart Question: How draw radar chart in delphi? Answer: This Component Draw radar chart for 1000 Items in 1000 dimension . the attach file is one demo .this demo show all ability of this component this demo code is : unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Radar, StdCtrls, ExtCtrls, Buttons, AdvLabel, QuickRpt, QRCtrls, Spin, Menus; type TRadarDemoForm = class(TForm) ColorDialog: TColorDialog; MainMenu1: TMainMenu; Panel6: TPanel; Panel8: TPanel; Panel1: TPanel; Panel2: TPanel; Panel7: TPanel; Panel3: TPanel; Label_AxisDivision: TLabel; Label_AxisLineWidth: TLabel; CheckBox_ShowAxisText: TCheckBox; BitBtn_AxisTextFont: TBitBtn; BitBtn_AxisLineColor: TBitBtn; SpinEdit_AxisDivision: TSpinEdit; SpinEdit_AxisLineWidth: TSpinEdit; CheckBox_ShowAxisLine: TCheckBox; Panel4: TPanel; Panel5: TPanel; Panel9: TPanel; Label4: TLabel; About1: TMenuItem; About2: TMenuItem; Label6: TLabel; OtherProduct1: TMenuItem; FontDialog: TFontDialog; BitBtn1: TBitBtn; Label2: TLabel; SpinEdit_AxisItemQuantity: TSpinEdit; Label7: TLabel; CheckBox_ShowAxisGridLine: TCheckBox; Panel10: TPanel; Radar: TRadar; CheckBox_ShowRadarBorder: TCheckBox; SpinEdit_RadarBorderLineWidth: TSpinEdit; Label_RadarLineWidth: TLabel; BitBtn_RadarBorderColor: TBitBtn; BitBtn_RadarBackGround: TBitBtn; BitBtn_RadarItems: TBitBtn; BitBtn_RadarZoomIn: TBitBtn; BitBtn_RadarZoomOut: TBitBtn; procedure About2Click(Sender: TObject); procedure ExitDemo1Click(Sender: TObject); procedure OtherProduct1Click(Sender: TObject); procedure BitBtn_RadarItemsClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure BitBtn_AxisLineColorClick(Sender: TObject); procedure BitBtn_AxisTextFontClick(Sender: TObject); procedure BitBtn_RadarBorderColorClick(Sender: TObject); procedure BitBtn_RadarBackGroundClick(Sender: TObject); procedure BitBtn_RadarZoomInClick(Sender: TObject); procedure BitBtn_RadarZoomOutClick(Sender: TObject); procedure CheckBox_ShowAxisLineClick(Sender: TObject); procedure SetObjectsEnabled(); procedure CheckBox_ShowAxisTextClick(Sender: TObject); procedure CheckBox_ShowRadarBorderClick(Sender: TObject); procedure BitBtn1Click(Sender: TObject); Procedure RadarDraw(); procedure SpinEdit_AxisLineWidthChange(Sender: TObject); procedure SpinEdit_AxisDivisionChange(Sender: TObject); procedure SpinEdit_RadarBorderLineWidthChange(Sender: TObject); procedure CheckBox_ShowAxisGridLineClick(Sender: TObject); procedure SpinEdit_AxisItemQuantityChange(Sender: TObject); private { Private declarations } public { Public declarations } end; var RadarDemoForm: TRadarDemoForm; AxisItemsName : array [1..40] of string=( 'Item 1','Item 2','Item 3','Item 4', 'Item 5','Item 6','Item 7','Item 8', 'Item 9','Item 10','Item 11','Item 12', 'Item 13','Item 14','Item 15','Item 16', 'Item 17','Item 18','Item 19','Item 20', 'Item 21','Item 22','Item 23','Item 24', 'Item 25','Item 26','Item 27','Item 28', 'Item 29','Item 30','Item 31','Item 32', 'Item 33','Item 34','Item 35','Item 36', 'Item 37','Item 38','Item 39','Item 40' ); RadarItemsName : array [1..10] of string= ('Radar Item 1','Radar Item 2','Radar Item 3','Radar Item 4','Radar Item 5' ,'Radar Item 6','Radar Item 7','Radar Item 8','Radar Item 9','Radar Item 10'); RadarItemsCount : word=2; AxisItemsCount : word=5; Value : array [1..10,1..40] of TValueLimit=( (1,3,2,5,3,4,9,2,7,3,5,2,5,7,4,8,5,2,6,3,2,7,2,4,2,4,5,7,8,0,4,1,2,2,4,6,3,2,4,6), (2,1,5,6,2,4,5,2,1,2,4,1,2,5,4,2,1,3,2,4,8,1,3,2,2,5,7,4,7,0,9,2,4,5,6,8,3,8,3,2), (2,2,6,3,2,7,1,2,7,6,4,6,8,2,3,2,7,0,9,2,4,3,6,4,3,8,3,2,2,7,9,2,7,3,1,2,5,7,4,8), (2,1,6,3,2,7,3,2,7,3,1,2,5,4,4,8,5,2,4,1,0,2,5,6,4,6,4,2,3,5,4,1,8,4,3,2,5,6,4,9), (2,3,5,4,5,8,4,3,5,5,6,4,5,4,5,6,8,3,8,3,2,7,3,7,9,2,4,6,8,4,3,2,5,6,4,9,4,5,6,8), (3,2,4,9,0,4,9,2,9,0,5,2,5,7,4,8,5,8,6,5,4,7,6,4,2,4,5,7,8,0,6,1,2,2,4,6,3,5,4,2), (4,4,5,8,4,4,5,2,2,7,4,1,2,5,6,7,8,3,2,4,8,1,7,8,2,5,7,4,7,8,7,2,4,5,7,8,3,6,3,3), (6,2,6,7,7,7,1,2,7,3,4,6,6,5,3,2,2,0,9,2,4,3,6,4,9,7,3,2,2,7,9,6,7,3,6,5,5,6,4,4), (7,3,7,3,8,7,2,2,7,3,0,2,2,4,4,8,5,2,2,1,0,2,5,6,4,6,5,2,6,5,4,5,8,4,6,4,4,5,4,9), (8,5,8,2,5,8,3,3,5,5,6,4,5,4,5,6,8,3,8,3,2,7,3,7,9,3,4,5,8,4,3,2,7,6,7,9,4,5,6,2) ); ValueColor : Array [1..10] of TColor=(clRed,clNavy,clBlue,clMaroon,clGreen, clBlack,clOlive,clCream,clAqua,clPurple); ValueLineWidth : Array [1..10] of TWidthLimit =(2,2,2,2,2,2,2,2,2,2); ValueShow : Array [1..10] of boolean=(True,True,False,False,False, False,False,False,False,False); implementation uses About,OtherProduct,RadarItems; {$R *.dfm} {-----------------------------------------------------------} procedure TRadarDemoForm.About2Click(Sender: TObject); var AboutForm : TAboutForm; begin AboutForm:=TAboutForm.Create(nil); AboutForm.ShowModal; AboutForm.Free; end; {-----------------------------------------------------------} procedure TRadarDemoForm.ExitDemo1Click(Sender: TObject); begin close; end; {-----------------------------------------------------------} procedure TRadarDemoForm.OtherProduct1Click(Sender: TObject); var OtherProductform : TOtherProductform; begin OtherProductform:=TOtherProductform.Create(nil); OtherProductform.ShowModal; OtherProductform.Free; end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_RadarItemsClick(Sender: TObject); var RadarItemsForm : TRadarItemsForm; i,k,j : integer; begin RadarItemsForm:=TRadarItemsForm.Create(nil); k:=High(RadarItemsName); for i:=1 to k do begin RadarItemsForm.ListBox_RadarItem.Items.Add(RadarItemsName[i]); RadarItemsForm.ListBox_RadarItem.Checked[i-1]:=ValueShow[i]; for j:=1 to 40 do TempValue[i][j]:=Value[i][j]; TempValueColor[i]:=ValueColor[i]; TempValueLineWidth[i]:=ValueLineWidth[i]; TempAxisCount:=AxisItemsCount; end; Radar.Clear; RadarItemsForm.ShowModal; RadarItemsCount:=0; for i:=1 to k do begin ValueShow[i]:=RadarItemsForm.ListBox_RadarItem.Checked[i-1]; ValueColor[i]:=TempValueColor[i]; ValueLineWidth[i]:=TempValueLineWidth[i]; if ValueShow[i] then begin RadarItemsCount:=RadarItemsCount+1; Radar.AddItem(AxisItemsName[i],Value[i],valuecolor[i],ValueLineWidth[i]); end; end; RadarItemsForm.Free; SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.FormCreate(Sender: TObject); var i,k : integer; begin k:=RadarItemsCount; for i:=1 to k do Radar.AddItem(AxisItemsName[i],Value[i],valuecolor[i],ValueLineWidth[i]); SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.SetObjectsEnabled(); begin if Radar.Zoomin=1 then BitBtn_RadarZoomOut.Enabled:=false else BitBtn_RadarZoomOut.Enabled:=true; if Radar.Zoomin=10 then BitBtn_RadarZoomIn.Enabled:=false else BitBtn_RadarZoomIn.Enabled:=true; if CheckBox_ShowAxisLine.Checked then Radar.Axis.BorderLineShow:=True else Radar.Axis.BorderLineShow:=False; if CheckBox_ShowAxisGridLine.Checked then Radar.Axis.GridLineShow:=True else Radar.Axis.GridLineShow:=False; Radar.Axis.AxisLines.LineWidth:=SpinEdit_AxisLineWidth.Value; Radar.AxisDivision:=SpinEdit_AxisDivision.Value; if CheckBox_ShowAxisText.Checked then Radar.Axis.AxisText.TextShow:=True else Radar.Axis.AxisText.TextShow:=False; if CheckBox_ShowRadarBorder.Checked then Radar.Border:=True else Radar.Border:=False; Radar.BorderWidth:=SpinEdit_RadarBorderLineWidth.Value; RadarDraw(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_AxisLineColorClick(Sender: TObject); begin if ColorDialog.Execute then begin Radar.Axis.AxisLines.LineColor:=ColorDialog.Color; SetObjectsEnabled(); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_AxisTextFontClick(Sender: TObject); begin if FontDialog.Execute then begin Radar.Axis.AxisText.TextFont:=FontDialog.Font; SetObjectsEnabled(); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_RadarBorderColorClick(Sender: TObject); begin if ColorDialog.Execute then begin Radar.BorderColor:=ColorDialog.Color; SetObjectsEnabled(); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_RadarBackGroundClick(Sender: TObject); begin if ColorDialog.Execute then begin Radar.BackGroundColor:=ColorDialog.Color; SetObjectsEnabled(); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_RadarZoomInClick(Sender: TObject); begin if Radar.Zoomin begin Radar.Zoomin:=Radar.Zoomin+1; SetObjectsEnabled(); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn_RadarZoomOutClick(Sender: TObject); begin if Radar.Zoomin1 then begin Radar.Zoomin:=Radar.Zoomin-1; SetObjectsEnabled(); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.CheckBox_ShowAxisLineClick(Sender: TObject); begin if CheckBox_ShowAxisLine.Checked then begin Label_AxisLineWidth.Enabled:=true; Label_AxisDivision.Enabled:=true; SpinEdit_AxisDivision.Enabled:=true; SpinEdit_AxisLineWidth.Enabled:=true; BitBtn_AxisLineColor.Enabled:=true; end else begin Label_AxisLineWidth.Enabled:=false; Label_AxisDivision.Enabled:=false; SpinEdit_AxisDivision.Enabled:=false; SpinEdit_AxisLineWidth.Enabled:=false; BitBtn_AxisLineColor.Enabled:=false; end; SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.CheckBox_ShowAxisTextClick(Sender: TObject); begin if CheckBox_ShowAxisText.Checked then BitBtn_AxisTextFont.Enabled:=true else BitBtn_AxisTextFont.Enabled:=false; SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.CheckBox_ShowRadarBorderClick(Sender: TObject); begin if CheckBox_ShowRadarBorder.Checked then begin Label_RadarLineWidth.Enabled:=true; BitBtn_RadarBorderColor.Enabled:=true; SpinEdit_RadarBorderLineWidth.Enabled:=true; end else begin Label_RadarLineWidth.Enabled:=false; BitBtn_RadarBorderColor.Enabled:=false; SpinEdit_RadarBorderLineWidth.Enabled:=FALSE; end; SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.BitBtn1Click(Sender: TObject); begin Close; end; {-----------------------------------------------------------} Procedure TRadarDemoForm.RadarDraw(); var i,k : integer; begin k:=AxisItemsCount; Radar.Axis.Items.Clear; for i:=1 to k do Radar.Axis.Items.Add(AxisItemsName[i]); k:=RadarItemsCount; for i:=1 to k do begin Radar.Draw(i); end; end; {-----------------------------------------------------------} procedure TRadarDemoForm.SpinEdit_AxisLineWidthChange(Sender: TObject); begin SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.SpinEdit_AxisDivisionChange(Sender: TObject); begin SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.SpinEdit_RadarBorderLineWidthChange( Sender: TObject); begin SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.CheckBox_ShowAxisGridLineClick(Sender: TObject); begin SetObjectsEnabled(); end; {-----------------------------------------------------------} procedure TRadarDemoForm.SpinEdit_AxisItemQuantityChange(Sender: TObject); begin AxisItemsCount:=SpinEdit_AxisItemQuantity.Value; SetObjectsEnabled(); end; {-----------------------------------------------------------} end.