The
For this project, I explored data from the
As it’s a small pet project to try out my skills with the new Angular version, I also tried to use a combination of tools that was new for me and make it a bit more interesting. So the final stack looked like this:
I considered several options for data visualization tools, but Flexmonster stood out for its ability to handle the data volume efficiently and provide quick integration into my stack. It also has both charts and pivot functionality available out-of-the-box.
Let's create a basic Angular project with the following commands:
ng new flying-etiquette --no-standalone --ssr=false --style=css
cd flying-etiquette
Now we will continue with the data source configuration.
Let's create a PostgreSQL database and fill it with data from the CSV file so we can analyze passengers' feelings about certain behaviors.
I've used the
To manage the database, I've used
Connect DBeaver to your remote database in the following way:
Once the connection has been established, your database instance will appear in the Database Navigator list:
After downloading the
Once the data is imported, you will see the newly created table. Check if all columns and data were exported correctly.
Now we have a configured database. Searching through the guides on installing Flexmonster I discovered it has a special Data Server, that optimizes the work with different data sources. The process was also very straightforward so I decided to stick to this option. But let’s install the tool itself first.
To install and configure Flexmonster for our project, install Flexmonster CLI:
npm install -g flexmonster-cli
Flexmonster CLI provides quick and convenient access to all the Flexmonster tools.
Once the Flexmonster CLI is installed, open the newly created project in a rich text editor or an IDE of your choice. Personally, I use
Install Flexmonster Angular wrapper for our project using Flexmonster CLI:
flexmonster add ngx-flexmonster
Then, import FlexmonsterPivotModule
into src/app/app.module.ts
file located in our project:
import { FlexmonsterPivotModule } from 'ngx-flexmonster';
@NgModule({
// ...
imports: [
FlexmonsterPivotModule,
// Other imports
],
// ...
})
And import Flexmonster styles into src/styles.css
file:
@import "flexmonster/flexmonster.min.css";
Finally, insert the <fm-pivot>
directive in src/app/app.component.html
:
<fm-pivot
[toolbar]="true">
</fm-pivot>
If you start the project at this stage, you will see a pivot table, but it's empty. Let's fix this by connecting a PostgreSQL database and Flexmonster.
Now that Flexmonster has been added to the Angular project and our database has been created, we need to connect Flexmonster to the database. To do this, we need to use Flexmonster Data Server. Here's how this tool works:
The Data Server can be installed with the following command:
flexmonster add fds -r
The -r
flag will automatically open the Data Server after it's installed.
Let's establish a connection between the Data Server and the database:
Step 1. Click the "Add New Index" button:
Step 2. Fill in the information about the index so it is similar to the following and click "Create":
Here's a connection string to the sample PostgreSQL database:
Server=stampy.db.elephantsql.com;Port=5432;Database=jvdheadr;User Id=jvdheadr;Password=4O7qgJ2C9VONkyn0Bp57V1I2EFggBhXd;
Now let's connect Flexmonster Pivot to the Data Server. Specify the [report]
attribute for the <fm-pivot>
directive in the following way:
<fm-pivot
[toolbar]="true"
[report]="{
dataSource: {
type: 'api',
// The Data Server runs on the 9500 by default
url: 'http://localhost:9500',
// Corresponds to the index name specified in the Data Server
index: 'flying-etiquette'
}
}">
</fm-pivot>
Finally, let's preset which fields should be displayed in the pivot table, so we can visualize data as soon as the page loads:
<fm-pivot
[toolbar]="true"
[report]="{
dataSource: {
type: 'api',
url: 'http://localhost:9500',
index: 'flying-etiquette'
},
slice: {
// Fields displayed in rows
rows: [{
uniqueName: 'Is it rude to knowingly bring unruly children on a plane?',
// Filter blank members
filter: { exclude: [''] }
}],
// Fields displayed in columns
columns: [{
uniqueName: 'Gender',
// Filter blank members
filter: { exclude: [''] }
},
{
uniqueName: '[Measures]'
}],
// Measures
measures: [{
uniqueName: 'RespondentID',
aggregation: 'count'
}]
}
}">
</fm-pivot>
And that's it! Our project is ready. Let's start it by running the following command:
npm start
When the project is built, you will see the pivot table and be able to analyze the data.
You can get the ready-to-use version of this project
The overall process of creating an Angular app, embedding the visualization tool and connecting it to PostgreSQL is pretty straightforward and fast to perform. So you can easily use this as a tutorial or an example for your Angular reporting application. Plus, now you get to know things people consider the rudest to do on your airplane trip!)