In this article, we'll look at how to create a cube in FastCube .NET using code in a custom application. This question will appear to you right away, when you start working with this library. Well, I hope today we will clarify this issue.
The cube file can contain both data and its’ representation. Let's look at the whole chain of the cube creation.
Create a Windows Forms project. In References, you need to add links to the libraries: FastReport, FastReport.Bars, FastReport.Olap.
Add the following controls to the form from the toolbar:
dataSource, dtDataSet, cube, slice, sliceGrid, button.
In the dataSource1 properties, we find the DataSet and select the available dtDataSet1 for it.
In the properties of the cube1 control, we select the value dataSource1 for the DataSource. And for the SoutceType property, the value is DataSource
In the slice1 properties, select the cube1 value for the Cube property.
Adjust the size of sliceGrid1. In its properties, select the slice1 value for Slice.
Now go to the form code.
First of all, let's add libraries to the Using section:
Add the following variables and objects to the class:
Here it is necessary to clarify that we will fill the table with fake data, just to demonstrate the possibility of software data generation. In addition to the DataTable, we can use a database or stream to retrieve data.
Create a DataTable and fill it with random data:
So, we have prepared a data source. I'll remind you that you can use a table or view from the database, or a data stream.
Add fields to the slice.
Now, create the OnClick event handler for our only button on the form. And write the following code:
That's all. Dimensions and measures are stored in separate containers. First we filled the YAxisContainer with dimensions. Then, an empty list of measures was added to XAxisContainer. And only then began to fill it with measures. This order is important for the correct display of data.
To make it clearer wherewith we fill out the list of measures, I'll give the signature of the constructor of the class MeasureField:
public MeasureField(Slice slice, AggregateFunction aggregateFunction, SliceField baseSliceField, SliceField distinctSliceField, SliceField extraSliceField, string name, string caption, bool distinct);
In the final line of our code, we store the cube in the specified file.
Now start the application and create a new cube using the buttons:
As you can see, it's quite easy to create a cube in the application code. It is more difficult to prepare data for it. But we'll talk about the data for the cube in another article.