DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Setting up Push Notifications in Ionic Capacitor for iOS
  • Ionic App Development Over Other Frameworks: Is It Hyped?
  • Performance Optimization Techniques in Flutter 3.41 for Mobile App Development
  • GraphQL vs REST — Which Is Better?

Trending

  • How SaaS Architectures Break at Scale — and the Engineering Decisions That Prevent It
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  • How to Save Money Using Custom LLMs for Specific Tasks
  • A Walk-Through of the DZone Article Editor
  1. DZone
  2. Data Engineering
  3. Data
  4. Interactive Data Visualization in Ionic 5

Interactive Data Visualization in Ionic 5

In a step-by-step tutorial, learn how to create an interactive mobile reporting solution with Ionic 5 and a JavaScript pivot table library.

By 
Veronika Rovnik user avatar
Veronika Rovnik
·
Aug. 31, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
8.1K Views

Join the DZone community and get the full member experience.

Join For Free

Hi everyone!

In this tutorial, I'd like to show you how to create a simple yet powerful reporting app with a native look and feel using Ionic 5 and Flexmonster Pivot Table & Charts — a JavaScript pivot table component that integrates with React, Angular, and Vue. 

But first, let me do a quick reminder of what Ionic is and what benefits it can bring to web development. 

If you are a seasoned pro in Ionic, skip this section and jump straight to the tutorial. 

What Is Ionic Used for? 

Ionic is a framework that provides a toolkit for creating production-ready mobile apps and progressive web apps.

All you need is to use web technologies you got used to.

Using a single codebase, you can create and run an app on any platform. Besides, Ionic is framework-agnostic, meaning you can integrate it with any front-end framework. Most popular are React, Angular, and Vue (official integration is coming soon). 

Another plus is that you can access native device features with just a little bit of JavaScript. 

Besides, you can always rely on the community's help - there are lots of plugins, starters, templates, and themes to help you keep moving forward. Using them in your projects is time-saving - no need to build every piece of functionality from scratch. 

Creating a Reporting App in Ionic

What will you get as a result?

After the tutorial completion, you'll get an analytics reporting app running. You can deliver it to end-users as a tool for in-depth data analysis. The layout and design of the app will depend on your specific case. You can treat this tutorial as a general approach to building reporting software. 

Here's a brief overview of features your project will be empowered with:

  • Composing reports with drag & drop 

  • Aggregating, grouping, filtering, and sorting data interactively 

  • Highlighting what matters most with formatting

  • Saving & exporting reports with a few clicks

And more!

Prerequisites

  • Node.js and npm on your machine

  • The Ionic CLI

And a desire to create an awesome app!

Starting an Ionic Project

We're going to use React as a front-end framework for the Ionic app. If you'd like to repeat the process in Angular, check out the links in the reference below.

Following the steps from the official guide, create a basic Ionic app. Skip this step if you already have an app. 

Next, add the Flexmonster React module:

PowerShell
xxxxxxxxxx
1
 
1
yarn add react-flexmonster --dev

 

Open index.tsx and import the styles of a pivot table control:

import 'flexmonster/flexmonster.css';

Open src/App.tsx and include the FlexmonsterReact package here:

import * as FlexmonsterReact from 'react-flexmonster';

Right there, create a report based on your data. I took the "Apple mobility trends" dataset from Kaggle and put the CSV file to the public/assets folder. Our report will show the average mobility values by months in different regions. 

TypeScript
xxxxxxxxxx
1
53
 
1
onReady(): void {
2
    var pivotObject = this.flexmonsterRef.current as FlexmonsterReact.Pivot;
3
    var report = {
4
      dataSource: {
5
        type: "csv",
6
        filename: "./assets/data.csv",
7
        mapping: {
8
          geo_type: {
9
            type: "string",
10
            caption: "Geo Type",
11
          },
12
          region: {
13
            type: "string",
14
            caption: "Region",
15
          },
16
          transportation_type: {
17
            type: "string",
18
            caption: "Transportation Type",
19
          },
20
          date: {
21
            type: "date",
22
            caption: "Date",
23
          },
24
          value: {
25
            type: "number",
26
            caption: "Value",
27
          },
28
        },
29
      },
30
      slice: {
31
        rows: [
32
          {
33
            uniqueName: "region",
34
          },
35
        ],
36
        columns: [
37
          {
38
            uniqueName: "date.Month",
39
          },
40
          {
41
            uniqueName: "[Measures]",
42
          },
43
        ],
44
        measures: [
45
          {
46
            uniqueName: "value",
47
            aggregation: "average"
48
          },
49
        ],
50
      }
51
    };
52
    pivotObject.flexmonster.setReport(report);
53
  }


Here, the mapping object is defined to prettify the captions of the fields and set their data types explicitly. 

Next, embed the pivot table component and set the previously defined report:

TypeScript
xxxxxxxxxx
1
12
 
1
render = () => {
2
    return (
3
      <IonApp>
4
        <FlexmonsterReact.Pivot
5
          ref={this.flexmonsterRef}
6
          toolbar={true}
7
          width="100%"
8
          ready={() => this.onReady()}
9
        />
10
      </IonApp>
11
    );
12
  };


Run the app:

npm run start

Creating a Dashboard

Now you have a pivot table that shows the summarized data in your Ionic app. But what if you want to add more visualization elements to the web page?

Here's where the concept of dashboard comes in handy. A dashboard usually consists of different data visualization components that show data from multiple angles and help answer the question that a data analyst is posing. 

Let's create an interactive dashboard by adding one more element to the page - Pivot Charts. 

It can be done in the same way as for the pivot table. The only difference is that you need to turn on the chart mode using options. 

Here we composed a slightly different report that highlights other aspects of data:

TypeScript
xxxxxxxxxx
1
49
 
1
var report = {
2
    "dataSource": {
3
        "type": "csv",
4
        "filename": "./assets/data.csv"
5
    },
6
    "slice": {
7
        "rows": [
8
            {
9
                "uniqueName": "region",
10
                "filter": {
11
                    "measure": {
12
                        "uniqueName": "value",
13
                        "aggregation": "average"
14
                    },
15
                    "query": {
16
                        "top": 10
17
                    }
18
                }
19
            }
20
        ],
21
        "columns": [
22
            {
23
                "uniqueName": "[Measures]"
24
            }
25
        ],
26
        "measures": [
27
            {
28
                "uniqueName": "value",
29
                "aggregation": "average"
30
            }
31
        ],
32
        "sorting": {
33
            "column": {
34
                "type": "desc",
35
                "tuple": [],
36
                "measure": {
37
                    "uniqueName": "value",
38
                    "aggregation": "average"
39
                }
40
            }
41
        }
42
    },
43
    "options": {
44
        "viewType": "charts",
45
        "chart": {
46
            "type": "bar_h"
47
        }
48
    }
49
}

Result

You're all set!

Dashboard in the Ionic web app

Dashboard in the Ionic web app

Deploying Mobile

The next step is to deploy the app on a mobile platform of your choice. Check out recommendations and guidelines on deployment on the official Ionic website. 

Once you are done, let's test the app on a mobile device using a device emulator of Android Studio or Xcode. 

Here's how your mobile dashboard looks on iPhone 5/SE:

Excel app in Ionic mobile app

To style up the app, you can use the beautiful Ionic UI components. 

Useful Links

  • How to build an Ionic app with React

  • A dashboard project on GitHub 

  • Your First Ionic App: Angular

  • Flexmonster Pivot Table & Charts: Integration with Ionic 

Ionic (mobile app framework) Data visualization mobile app Pivot table

Opinions expressed by DZone contributors are their own.

Related

  • Setting up Push Notifications in Ionic Capacitor for iOS
  • Ionic App Development Over Other Frameworks: Is It Hyped?
  • Performance Optimization Techniques in Flutter 3.41 for Mobile App Development
  • GraphQL vs REST — Which Is Better?

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook