2016-09-06 14 views
0

当社のアプリケーションでは、会社の複数の支店の時間に対するパーセンテージ値を示すために、次のコードがあります。ブランチ名はカスタムチェックボックスパネルに表示され、チェックボックスを追加して特定のブランチを表示するかどうかを動的に指定できます。ボタンをクリックすると、クエリを開くための手順があり、チャートにシリーズを表示する必要があります。ただし、シリーズは表示されません。クエリはデータを返し、グラフの軸はクエリによって返される値の範囲に合わせて変更されます。これはもともとDelphi 10で開発されたものですが、現在はDelphi XE7では動作していません。Delphi XE7 - TDBChartがシリーズを表示しない

type 
    TBranchItem = class 
    procedure CheckBoxClick(Sender: TObject); 
    private 
    FColour: TColor; 
    public 
    BranchID: integer; 
    Query: TADOQuery; 
    CheckBox: TCheckBox; 
    property Colour: TColor read FColour write FColour; 

    constructor Create(const Connection: TADOConnection); 
    destructor Destroy; 

    end; 

    TfrmGiftAidBranchSummary = class(TfrmBaseMts) 
    Panel1: TPanel; 
    mtsBackButton1: TmtsBackButton; 
    chGAProportion: TDBChart; 
    Q: TADOQuery; 
    cbpBranches: TCheckBoxPanel; 
    Panel2: TPanel; 
    edStartMonth: TEdit; 
    Label1: TLabel; 
    Label2: TLabel; 
    edEndMonth: TEdit; 
    lblStartDate: TLabel; 
    lblEndDate: TLabel; 
    btnDraw: TmtsButton; 
    chkIncluderefunds: TCheckBox; 
    procedure FormShow(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure mtsBackButton1Click(Sender: TObject); 
    procedure btnDrawClick(Sender: TObject); 
    procedure edStartMonthChange(Sender: TObject); 
    procedure edEndMonthChange(Sender: TObject); 
    private 
    { Private declarations } 
    FColourArray: array[0..99] of TColor; 
    FBranchItemArray: array of TBranchItem; 

    procedure FillColourArray; 
    procedure DrawGAProportionChart; 
    procedure CreateBranchItems; 
    public 
    { Public declarations } 
    end; 


var 
    frmGiftAidBranchSummary: TfrmGiftAidBranchSummary; 

implementation 

{$R *.dfm} 

{ TfrmGiftAidBranchSummary } 

procedure TfrmGiftAidBranchSummary.btnDrawClick(Sender: TObject); 
begin 
    inherited; 
    Screen.Cursor := crHourGlass; 
    DrawGAProportionChart; 
    Screen.Cursor := crDefault; 
end; 

procedure TfrmGiftAidBranchSummary.CreateBranchItems; 
var 
    Count: integer; 
    LineSeriesArray: array of TChartSeries; 
begin 
    Q.Close; 
    Q.SQL.Clear; 
    Q.SQL.Add('SELECT BranchID, Name FROM BranchTransfer'); 
    Q.SQL.Add('WHERE Webshop = 0 AND BranchController = 0'); 
    Q.SQL.Add('AND BranchID > 0'); 
    Q.SQL.Add('ORDER BY BranchID'); 
    Q.Open; 

    Count := 0; 

    SetLength(FBranchItemArray, Q.RecordCount); 
    SetLength(LineSeriesArray, Q.RecordCount); 

    while not Q.Eof do 
    begin 
    FBranchItemArray[Count] := TBranchItem.Create(dmMainDataModule.dbMTS); 
    FBranchItemArray[Count].BranchID := Q.FieldByName('BranchID').AsInteger; 
    FBranchItemArray[Count].Colour := FColourArray[Count]; 
    FBranchItemArray[Count].CheckBox := cbpBranches.AddCheckBox(Q.FieldByName('Name').AsString, True, FBranchItemArray[Count].Colour); 
    FBranchItemArray[Count].CheckBox.OnClick := FBranchItemArray[Count].CheckBoxClick; 

    FBranchItemArray[Count].Query.Close; 
    FBranchItemArray[Count].Query.SQL.Clear; 
    FBranchItemArray[Count].Query.SQL.Add('SELECT A.BranchID, DonatedValue, GiftAidValue, A.month_no,'); 
    FBranchItemArray[Count].Query.SQL.Add('CASE WHEN DonatedValue = 0 THEN 0 ELSE (GiftAidValue/DonatedValue) * 100 END AS GAProportion'); 
    FBranchItemArray[Count].Query.SQL.Add('FROM'); 
    FBranchItemArray[Count].Query.SQL.Add('(SELECT branchid, SUM(value) AS DonatedValue, month_no from audit'); 
    FBranchItemArray[Count].Query.SQL.Add('WHERE trans_type in (''CS'', ''CRS'', ''VS'')'); 
    FBranchItemArray[Count].Query.SQL.Add('AND stock_type = ''G'''); 
    FBranchItemArray[Count].Query.SQL.Add('AND BranchID = ' + IntToStr(FBranchItemArray[Count].BranchID)); 
    FBranchItemArray[Count].Query.SQL.Add('AND Month_no >= ' + edStartMonth.Text); 
    FBranchItemArray[Count].Query.SQL.Add('AND Month_no <= ' + edEndMonth.Text); 
    FBranchItemArray[Count].Query.SQL.Add('AND Qty > 0'); 
    FBranchItemArray[Count].Query.SQL.Add('GROUP BY BranchID, month_no) A'); 
    FBranchItemArray[Count].Query.SQL.Add('LEFT Join'); 
    FBranchItemArray[Count].Query.SQL.Add('(SELECT branchid, SUM(value) AS GiftAidValue, month_no from audit'); 
    FBranchItemArray[Count].Query.SQL.Add('WHERE trans_type in (''CS'', ''CRS'', ''VS'')'); 
    FBranchItemArray[Count].Query.SQL.Add('AND stock_type = ''G'''); 
    FBranchItemArray[Count].Query.SQL.Add('AND Month_no >= ' + edStartMonth.Text); 
    FBranchItemArray[Count].Query.SQL.Add('AND Month_no <= ' + edEndMonth.Text); 
    FBranchItemArray[Count].Query.SQL.Add('AND Qty > 0'); 
    FBranchItemArray[Count].Query.SQL.Add('AND DonorAccountID IN (SELECT Account_id FROM customer WHERE GiftAid <> 0)'); 
    FBranchItemArray[Count].Query.SQL.Add('AND BranchID = ' + IntToStr(FBranchItemArray[Count].BranchID)); 
    FBranchItemArray[Count].Query.SQL.Add('GROUP BY BranchID, month_no) G'); 
    FBranchItemArray[Count].Query.SQL.Add('ON A.BranchID = G.BranchID'); 
    FBranchItemArray[Count].Query.SQL.Add('and A.month_no = G.month_no'); 
    FBranchItemArray[Count].Query.SQL.Add('ORDER BY month_no, BranchID'); 

    LineSeriesArray[Count] := TChartSeries.Create(chGAProportion); 
    LineSeriesArray[Count].ParentChart := chGAProportion; 
    LineSeriesArray[Count].DataSource := FBranchItemArray[Count].Query; 
    LineSeriesArray[Count].CheckDatasource; 
    LineSeriesArray[Count].YValues.ValueSource := 'GAProportion'; 
    LineSeriesArray[Count].XValues.ValueSource := 'Month_no'; 
    LineSeriesArray[Count].XLabelsSource := 'Month_no'; 
    LineSeriesArray[Count].SeriesColor := FColourArray[Count]; 
    LineSeriesArray[Count].Pen.Width := 2; 

    SetChecked(FBranchItemArray[Count].CheckBox, True); 

    Inc(Count); 
    Q.Next; 
    end; 

    chGAProportion.AddSeries(LineSeriesArray); 
end; 

procedure TfrmGiftAidBranchSummary.DrawGAProportionChart; 
var 
    i: Integer; 
begin 
    for i := 0 to Length(FBranchItemArray) - 1 do 
    begin 
    FBranchItemArray[i].Query.Close; 

    FBranchItemArray[i].Query.SQL[7] := 'AND Month_no >= ' + edStartMonth.Text; 
    FBranchItemArray[i].Query.SQL[8] := 'AND Month_no <= ' + edEndMonth.Text; 
    FBranchItemArray[i].Query.SQL[15] := 'AND Month_no >= ' + edStartMonth.Text; 
    FBranchItemArray[i].Query.SQL[16] := 'AND Month_no <= ' + edEndMonth.Text; 


    if chkIncluderefunds.Checked then 
    begin 
     FBranchItemArray[i].Query.SQL[9] := ''; 
     FBranchItemArray[i].Query.SQL[17] := ''; 
    end 
    else 
    begin 
     FBranchItemArray[i].Query.SQL[9] := 'AND Qty > 0'; 
     FBranchItemArray[i].Query.SQL[17] := 'AND Qty > 0'; 
    end; 

    if FBranchItemArray[i].CheckBox.Checked then 
     FBranchItemArray[i].Query.Open; 
    end; 

end; 

procedure TfrmGiftAidBranchSummary.edEndMonthChange(Sender: TObject); 
begin 
    inherited; 
    Q.Close; 
    Q.SQL.Clear; 
    Q.SQL.Add('SELECT MAX(trans_date) AS trans_date FROM audit WHERE Month_no = ' + edEndMonth.Text); 
    Q.Open; 

    if not (Q.Bof and Q.Eof) then 
    lblEndDate.Caption := FormatDateTime('dd/mm/yy', Q.FieldByName('trans_date').AsDateTime) 
    else 
    lblEndDate.Caption := 'Not Found'; 
end; 

procedure TfrmGiftAidBranchSummary.edStartMonthChange(Sender: TObject); 
begin 
    inherited; 
    Q.Close; 
    Q.SQL.Clear; 
    Q.SQL.Add('SELECT MIN(trans_date) AS trans_date FROM audit WHERE Month_no = ' + edStartMonth.Text); 
    Q.Open; 

    if not (Q.Bof and Q.Eof) then 
    lblStartDate.Caption := FormatDateTime('dd/mm/yy', Q.FieldByName('trans_date').AsDateTime) 
    else 
    lblStartDate.Caption := 'Not Found'; 
end; 

{ TBranchItem } 

procedure TBranchItem.CheckBoxClick(Sender: TObject); 
begin 
    if Checkbox.Checked then 
    Query.Open 
    else 
    Query.Close; 
end; 

constructor TBranchItem.Create(const Connection: TADOConnection); 
begin 
    Query := TADOQuery.Create(nil); 
    Query.Connection := Connection; 
end; 

destructor TBranchItem.Destroy; 
begin 
    Query.Free; 
end; 

procedure TfrmGiftAidBranchSummary.FillColourArray; 
begin 
    FColourArray[0] := $008080; 
    FColourArray[1] := $FFB6C1; 
    FColourArray[2] := $00FFFF; 
    FColourArray[3] := $7FFFD4; 
    FColourArray[4] := $000000; 
    FColourArray[5] := $FFEBCD; 
    FColourArray[6] := $0000FF; 
    FColourArray[7] := $8A2BE2; 
    FColourArray[8] := $A52A2A; 
    FColourArray[9] := $DEB887; 
    FColourArray[10] := $5F9EA0; 
    FColourArray[11] := $7FFF00; 
    FColourArray[12] := $D2691E; 
    FColourArray[13] := $6495ED; 
    FColourArray[14] := $DC143C; 
    FColourArray[15] := $00008B; 
    FColourArray[16] := $008B8B; 
    FColourArray[17] := $B8860B; 
    FColourArray[18] := $A9A9A9; 
    FColourArray[19] := $006400; 
    FColourArray[20] := $BDB76B; 
    FColourArray[21] := $8B008B; 
    FColourArray[22] := $556B2F; 
    FColourArray[23] := $FF8C00; 
    FColourArray[24] := $9932CC; 
    FColourArray[25] := $8B0000; 
    FColourArray[26] := $E9967A; 
    FColourArray[27] := $8FBC8F; 
    FColourArray[28] := $483D8B; 
    FColourArray[29] := $2F4F4F; 
    FColourArray[30] := $00CED1; 
    FColourArray[31] := $9400D3; 
    FColourArray[32] := $FF1493; 
    FColourArray[33] := $00BFFF; 
    FColourArray[34] := $696969; 
    FColourArray[35] := $1E90FF; 
    FColourArray[36] := $B22222; 
    FColourArray[37] := $228B22; 
    FColourArray[38] := $FF00FF; 
    FColourArray[39] := $FFD700; 
    FColourArray[40] := $DAA520; 
    FColourArray[41] := $808080; 
    FColourArray[42] := $008000; 
    FColourArray[43] := $FF69B4; 
    FColourArray[44] := $CD5C5C; 
    FColourArray[45] := $4B0082; 
    FColourArray[46] := $7CFC00; 
    FColourArray[47] := $ADD8E6; 
    FColourArray[48] := $F08080; 
    FColourArray[49] := $90EE90; 
    FColourArray[50] := $D3D3D3; 
    FColourArray[51] := $FFA07A; 
    FColourArray[52] := $20B2AA; 
    FColourArray[53] := $87CEFA; 
    FColourArray[54] := $778899; 
    FColourArray[55] := $B0C4DE; 
    FColourArray[56] := $00FF00; 
    FColourArray[57] := $32CD32; 
    FColourArray[58] := $800000; 
    FColourArray[59] := $66CDAA; 
    FColourArray[60] := $0000CD; 
    FColourArray[61] := $BA55D3; 
    FColourArray[62] := $9370DB; 
    FColourArray[63] := $3CB371; 
    FColourArray[64] := $7B68EE; 
    FColourArray[65] := $00FA9A; 
    FColourArray[66] := $48D1CC; 
    FColourArray[67] := $C71585; 
    FColourArray[68] := $191970; 
    FColourArray[69] := $000080; 
    FColourArray[70] := $808000; 
    FColourArray[71] := $6B8E23; 
    FColourArray[72] := $FFA500; 
    FColourArray[73] := $FF4500; 
    FColourArray[74] := $DA70D6; 
    FColourArray[75] := $98FB98; 
    FColourArray[76] := $AFEEEE; 
    FColourArray[77] := $DB7093; 
    FColourArray[78] := $FFDAB9; 
    FColourArray[79] := $CD853F; 
    FColourArray[80] := $FFC0CB; 
    FColourArray[81] := $DDA0DD; 
    FColourArray[82] := $B0E0E6; 
    FColourArray[83] := $800080; 
    FColourArray[84] := $FF0000; 
    FColourArray[85] := $BC8F8F; 
    FColourArray[86] := $4169E1; 
    FColourArray[87] := $8B4513; 
    FColourArray[88] := $FA8072; 
    FColourArray[89] := $F4A460; 
    FColourArray[90] := $2E8B57; 
    FColourArray[91] := $A0522D; 
    FColourArray[92] := $C0C0C0; 
    FColourArray[93] := $87CEEB; 
    FColourArray[94] := $6A5ACD; 
    FColourArray[95] := $708090; 
    FColourArray[96] := $00FF7F; 
    FColourArray[97] := $4682B4; 
    FColourArray[98] := $D2B48C; 
    FColourArray[99] := $008080; 
end; 

procedure TfrmGiftAidBranchSummary.FormCreate(Sender: TObject); 
begin 
    inherited; 
    FillColourArray; 
end; 

procedure TfrmGiftAidBranchSummary.FormShow(Sender: TObject); 
begin 
    inherited; 
    with TADOQuery.Create(nil) do 
    try 
    Connection := dmMainDataModule.dbMTS; 

    Close; 
    SQL.Clear; 
    SQL.Add('SELECT month_no FROM Sequence'); 
    Open; 

    edStartMonth.Text := '1'; 

    if not (Q.Bof and Q.Eof) then 
     edEndMonth.Text := FieldByName('month_no').AsString 
    else 
     edEndMonth.Text := '1'; 
    finally 
    Free; 
    end; 

    CreateBranchItems; 
end; 

procedure TfrmGiftAidBranchSummary.mtsBackButton1Click(Sender: TObject); 
begin 
    inherited; 
    ModalResult := mrOK; 
end; 

答えて

0

解決済み。 LineSeriesArray[Count] := TChartSeries.Create(chGAProportion); の代わりに LineSeriesArray[Count] := TLineSeries.Create(chGAProportion); これを変更して正常に動作しているはずです。

関連する問題