Kompletní skript bez komentářů |
Top Previous Next |
const sSQL='SELECT top 20 jmeno, count(jmeno) as pocet FROM "DBA"."gfkontakt" '+ 'where jmeno is not null group by jmeno order by pocet desc'; fromCol=2; fromRow=4;
procedure FillChartData(col,row : integer ); var r,x,y : integer; ChartSer : TChartSeries; ser : TfrxSeriesItem; Chart : TfrxChartView; begin Chart:=TfrxChartView(SheetList[0].GetCellProperty([2,12]).frxReport.FindComponent('ChartB12')); if chart=nil then begin showmessage('Chart nil!'); exit; end;
// smaz series a seriesdata Chart.Chart.SeriesList.Clear; Chart.SeriesData.Clear;
// chart 3D options Chart.Chart.View3D:=True; Chart.Chart.View3DWalls:=True; Chart.Chart.View3DOptions.Orthogonal:=True; Chart.Chart.BottomAxis.LabelsAngle:=90;
// chart title Chart.Chart.Title.Text.Clear; Chart.Chart.Title.Text.Add('Jména');
ChartSer:=Chart.Chart.AddSeries( TBarSeries.Create(nil) ); TCustomBarSeries(ChartSer).Title:='jmena';
TCustomBarSeries(ChartSer).Marks.Visible := False; TCustomBarSeries(ChartSer).MultiBar:=mbSide; TCustomBarSeries(ChartSer).BarPen.Visible:=False; ChartSer.SeriesColor:=$0046DAFF;
ChartSer.Name:='jmena'; ser := Chart.SeriesData.Add; ser.DataType:=dtFixedData; ser.YSource := ''; ser.XSource := '';
// fill chart data ser := Chart.SeriesData.Items[0]; x:=col; with ser do begin for y:=1 to 2 do for x:=fromCol to fromCol+9 do begin if y=1 then r:=fromRow else r:=fromRow+3; XSource := XSource + Sheet.Cells(x,r)+';'; YSource := YSource + Sheet.Cells(x,r+1)+';'; end; end;
Sheet.GetCellProperty([2,12]).frxReport.ShowReport; end;
procedure LoadData; var Query : TQuery; i,r,list : integer; s : string; // Chart Page: TfrxReportPage; Chart : TfrxChartView; begin Sheet:=ReportProperty.NewSheet; Sheet.ColCount:=13; Sheet.RowCount:=14; // nadpis reportu Sheet.Cells[2,2]:='Top 20 names from gfkontakt'; // tucne, podtrzene Sheet.CellProperty[2,2].Font.Style:=fsBold+fsUnderline;
r:=0;i:=0; // load data Query:=TQuery.Create(nil); try Query.DatabaseName := DefaultDatabaseName; Query.SQL.Text:=sSQL; Query.Open;
while Not(Query.Eof) do begin Sheet.Cells[fromCol+i,fromRow+r ]:=Query.FieldbyName('jmeno').AsString; With Sheet.CellProperty[fromCol+i,fromRow+r] do begin Font.Style:=fsBold; Background:=$00FDBD97; Format:=1; end;
Sheet.Cells[fromCol+i,fromRow+r+1]:=Query.FieldbyName('pocet').AsString; With Sheet.CellProperty[fromCol+i,fromRow+r+1] do begin Font.Style:=fsBold; Background:=$0046DAFF; Format:=1; end;
inc(i); if i>9 then begin inc(r,3); i:=0; end;
Query.Next; end; finally Query.Free;
// vytvorime Chart Sheet.MergeCells(2,12,11,12); Sheet.Rows[12].Height:=400; Sheet.Rows.Group(12,12); ReportProperty.PlaceReport(Sheet,2,12); Page := TfrxReportPage.Create(Sheet.GetCellProperty([2,12]).frxReport); With Page do begin Name:='PageChartB12'; PaperWidth:=205; PaperHeight:=95; LeftMargin:=0; RightMargin:=0; TopMargin:=0; BottomMargin:=0; end;
Chart := TfrxChartView.Create(Page); Chart.Align:=6; // baClient; Chart.Name:='ChartB12'; FillChartData( 3, 11 ); // end Chart ReportProperty.SetModified(False); end; end;
procedure OnBeforeReport(Sender : TReportProperty); begin LoadData; end;
begin end. |