How to make a report based on the FastCube .NET cube

2018-04-03

Analysts, when dealing with cubes, sometimes need to generate reports, based on slices.

When is it necessary? When you need to make regular reports based on cubes. When you need to export a cube to some popular data format, which is not available in the built-in FastCube.Net export. Built-in FastCube export offers us 7 formats:

 

And FastReport .NET report - 24 formats. And additionally saving to cloud services, sending by e-mail and FTP:

 

In this article, I want to talk about such an excellent opportunity as to make a report based on a cube cut. By tradition, we will consider the example.

Create a WindowsForms application. Add to the project links to the libraries: FastReport, FastReport.Olap, FastReport.Bars. They can be found in the folder with installed FastCube.Net.

Add the following components to the form from the toolbar:

Cube, Slice, SliceGrid, Button

Let's configure the Slice1 component. For its cube property, we select cube1.

For the SliceGrid1 component we need to set the slice-slice1 property.

For the button, create the event handler for the click event:

1
2
3
4
5
6
7
8
9
private void button1_Click(object sender, EventArgs e)
 {
 SliceCubeReportLink SliceLink = new SliceCubeReportLink();
 SliceLink.Slice = slice1;
 cube1.Load("C:/Program Files (x86)/FastReports/FastCube.Net Professional/Demos/Data/Cubes/simple.mdc");
 Report FReport = new Report();
 FReport.RegisterData(SliceLink, "TestCubeLink");
 FReport.Design();
 }

 In the first line of code, we have created a SliceCubeReportLink object, which is responsible for providing the slice data for the report. Next, we assign the slice property a value of slice1 for the created object. That is, we specify where to get the data.

Now you need to load the cube file into the cube object. Since we are using a file with the mdc extension, it already contains the data inside and there is no need to create a connection to the data source for the cube.

Then we create a Report object, load the report template file into it, register the data source in it, and run the report in the designer.

If we do not need to make edits to the report template, then instead of starting the designer, it is better to run the report in the preview mode:

1
2
 FReport.Prepare();
 FReport.ShowPrepared();

 Let's now look at the report template. After all, we just pass the data from the cube into the report, and we'll have to create the cross-table template manually. That is, you will not be able to generate a report on the fly from any slice. You will always need a pre-prepared template.

To create a report template, we need to run the application, and then the report designer. This is the only way we get the data source for the report. Thus, the code for our button in its initial form, we use the designer's call:

1
 FReport.Design();

 Run the application. And press the report generation button:

This will start the report designer with an empty report. Notice the data area on the right:

It has a cube data source - TestCubeLink.

And now look at the vertical toolbar on the left. Namely icon . This is a CrossView component that will form a crosstab from the cube data source. "Drag" it to the "Data" band.

 

On the right find the CubeSource in the Property inspector

 

In the end, we'll get such report template:

We save it to the desired place. In my example it is stored in: C:/Program Files (x86)/FastReports/FastCube.Net Professional/Demos/Data/Cubes/Test.frx.

We close the application. Now modify the code for the button:

1
2
3
4
5
6
7
8
SliceCubeReportLink SliceLink = new SliceCubeReportLink();
 SliceLink.Slice = slice1;
 cube1.Load("С:/Program Files (x86)/FastReports/FastCube.Net Professional/Demos/Data/Cubes/simple.mdc");
 Report FReport = new Report();
 FReport.Load("С:/Program Files (x86)/FastReports/FastCube.Net Professional/Demos/Data/Cubes/Test.frx");
 FReport.RegisterData(SliceLink, "TestCubeLink");
 FReport.Prepare();
 FReport.ShowPrepared();

 Run the application and click the button. And we get a report:

 

From the preview mode of the report, we can export the report, send it by email and so on. This was the simplest example of a report. You can decorate a crosstab using the style property and get a much more attractive appearance:

October 28, 2024

How to Set Up WSL 2 for Working with FastReport and FastCube

In this article, we will explore how to set up WSL 2 for working with FastReport and FastCube components in Lazarus for Linux.
August 12, 2024

How to build and install the Postgres plugin in FastReport .NET

This article describes how to connect to the database using the FastReport .NET plugin for the report designer from Visual Studio via the NuGet server.
August 08, 2024

How to install FastReport .NET and its components on Windows

Step-by-step instructions for online and manual installation via the FastReport registration code.NET and its components in Windows.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.