PivotCube User's Guide Table of contents

Section 5

Section 6

Section 7


5. TPivotChart

TPivotChart is a wrapper component for the standard TeeChart component, so most of TPivotChart methods and properties are identical to those found in TChart.  In this section we describe only the additional properties introduced by PivotCube.

To use TPivotChart, set the Map property to an instance of TPivotMap.  The most important properties of TPivotChart are:

XAxis determines which data will be displayed on the chart's x-axis
ZAxis determines which data will be used to produce the set of chart series (graphs)
ColumnDeepLevel, RowDeepLevel

determines, cells of which level are used when TPivotChart is filled. Values 0, 1 - top level dimension, 2 - second level, 3 - third etc.
Note: TPivotChart does not expand cells, so if ColumnDeepLevel = 2 and items of top dimension on column is not expanded, TPivotChart will be empty.

TopRows,TopColumns default nil; determines which cell will used as top-level cell. Use with caution! For advanced users only!
Measure determines which measure will be displayed when both the xAxis or zAxis properties do not use pvcMeasures.

For example:

TPivotChart.Xaxis = pvcRows;
TPivotChart.Zaxis = pvcMeasures
TPivotChart.RowDeepLevel = 2
TPivotChart will display set of graphs by number of measures with row total values

TPivotChart.Xaxis = pvcColumns;
TPivotChart.Zaxis = pvcRows
TPivotChart will display set of graphs by number of rows with values for each column value.


5.1 Use TPivotChart to display non-top level dimension values (obsolete since v 6.5)

To create charts for nested dimensions, use the TopRow and TopColumn properties of TPivotChart.  By default, these properties have the value Null, which means that the top-most dimension is used.

For example, to display all clients (on columns), who buy wares (on rows, nested in Employers) shipped by employer named ‘Baldwin’, set the following properties

Chart.Xaxis =pvcColumns
Chart.Zaxis = pvcRows

for i := 0 to Map.Intf.RowCount – 1 do
begin
  if Map.Intf.Rows[I].Caption = ‘Baldwin’ then
  begin
    Chart.TopRow := Map.Intf.Rows[I];
    Break;
  end;
end;

Chart.Measure := Map.MeasureByName(‘Summa’);
Chart.RefreshData;

An alternative is to use the OnCustomChart event handler.  This allows you to fill and create charts at runtime.

Here is example where a chart is filled with all dimensions on second level by column:

procedure TForm1.PivotChart1CustomChart(Chart: TPivotChart; Kernel: IMap;
SeriesType: TChartSeriesClass; var Used: Boolean);
var
  i,j : integer;
  sr : TBarSeries;
  cell : ICell;

  function CreateCaption(Cell : ICell) : string; 
  // create caption as Cellcaption + 'OwnerCaption like 'April 2002' 'May 2002' etc
  begin
  if Cell.Owner = nil then
    Result := Cell.Caption
  else
    Result := Cell.Caption + ' ' + CreateCaption(Cell.Owner);
  end;

begin
  // check if 2 dimensions placed on columns and is top dimension expanded by at least one item
  if (Kernel.ColumnDimCount >= 2) and (Kernel.ColumnLevelCount = 2) then
  begin
    for i := 0 to Kernel.TopRows.ChildCount - 1 do // each series is one row on grid
    begin
      sr := TBarSeries.Create(Chart);
      sr.Title := Kernel.TopRows.Childs[i].Caption;
      sr.ShowInLegend := True;
      
      for j := 0 to Kernel.ColumnsCount - 1 do
      begin
        cell := Kernel.Columns[j];
        if cell.Level = 2 then // only cells from nested dimension will used
        begin
          if cell.IsNode and cell.NodeExpanded then Continue;
          if not cell.Visible then Continue;
          sr.Add(Kernel.Cells[cell.Position,Kernel.TopRows.Childs[i].Position,0],CreateCaption(cell));
          sr.Marks.Visible := False; 
        end;
      end;

      Chart.AddSeries(sr);
    end;

    Chart.ShowMarks := True;
    Used := True;
  end;
end;


6. Printing and exporting

PivotCube can export data to various formats, and can also print the contents of a TPivotGrid.

6.1 HTML

To save the current TPivotGrid data in HTML format to a file, use the method:

TPivotGrid.ExportToHTML(FileName: string; Progress, AutoOpen : boolean);

where

  • FileName is the name of the file where the data will be stored
  • Progress - set to True if you with to display a progress bar while exporting
  • AutoOpen - set to True if you wish to display the exported HTML file after the export has completed

Notes:

  • the HTML output keeps most of the color and font settings found in the source TPivotGrid.
  • the resulting file may be very large in size.

6.2 Microsoft Excel

To save the current TPivotGrid data into Microsoft Excel (via OLE), use the method:

PivotGrid.ExportToExcel(var ExcelApp : OleVariant)

where

  • ExcelApp is a pointer to an Excel Application OLE server.  If this parameter is nil, then a new instance of Excel will be created.

Notes:

  • Microsoft Excel must be installed on the workstation where you wish to perform the export.

6.3 TStringGrid

PivotCube allows you to export data into a simple TStringGrid instance, which can then be printed using third-party printing components that support printing of a TStringGrid.  Examples of such systems are FastReport, Express Printing System and Rave Reports.

6.4 Printing

You can print the contents of a TPivotGrid by calling the TPivotGrid.Print method.

procedure PivotGrid.Print(PageBounds : TRect; Preview : boolean; Quality : TpvGridPrintQuality; ClearTempFiles : boolean);

where
PageBounds : TRect - page bounds by page borders, in millimeters. PageBounds (20,10,5,10) will setup
Left border - 20 mm
Top border - 10 mm
Right border - 5 mm
Bottom border - 10 mm
Preview : Show/Hide preview form. If Preview is False , print job will start immediately.
Quality : Default printing quality.
pqBw - Black/White printing.  All visual styles will be converted to b/w visual styles - font color will be black, cell background color will be white.
pqFlat - Current color/font settings will used, but drawing style will be converted to flat mode
pqNative - Current visual style will be used for printing. You may use pqNative to define own look of grid before printing.

ClearTempFiles : Printing will create a set of Windows metaf