The requested page is not available for the requested platform. You are viewing the content for Default platform.

Client-Side Configuration (Angular)

  • 4 min to read

This approach is based on the client-server model. You need a server (backend) project and a client (frontend) application that includes all the necessary styles, scripts and HTML-templates. Note that the script version on the client should match with libraries version on the server up to a minor version.

The modular approach allows you to integrate the HTML JavaScript Dashboard control into web applications. This topic describes how to add the HTML JavaScript Dashboard control to an Angular application.

Prerequisites

  • Make sure you have Node.js and npm installed on your machine.
  • In the command prompt, install the Angular CLI (command line interface tool) globally:

    npm install -g @angular/cli
    

    Refer to the Angular documentation for information on the application's structure and the created files' purposes.

Requirements

  • The script version on the client should match with libraries version on the server up to a minor version.
  • Versions of the devexpress npm packages should be identical (their major and minor versions should be the same).

Create Angular Application

In the command prompt, create an Angular application and navigate to the created folder:

ng new dashboard-angular-app
cd dashboard-angular-app

Install Dashboard Package

The devexpress-dashboard npm package references devextreme and @devexpress/analytics-core as peerDependencies. The peerDependencies packages should be installed manually. This allows developers to control a version of the peerDependencies packages and guarantees that the package is installed once.

Install a dashboard package with required peerDependencies:

npm install devextreme @devexpress/analytics-core devexpress-dashboard --save

You can find all the libraries in the node_modules folder after the installation is completed.

Map Modules

In the tsconfig.json file, add paths for the globalize and cldrjs modules.

{ 
  "compilerOptions": { 
    // ...
    "paths": { 
        "jszip": [  
        "node_modules/jszip/dist/jszip.min.js"  
      ],  
      "globalize": [  
        "node_modules/globalize/dist/globalize"  
      ],  
      "globalize/*": [  
        "node_modules/globalize/dist/globalize/*"    
      ], 
      "cldr": [  
        "node_modules/cldrjs/dist/cldr"     
      ], 
      "cldr/*": [  
        "node_modules/cldrjs/dist/cldr/*"  
      ]
    }
  }
}

Create New Dashboard Component

In the console window, use the ng generate component command to generate a new Dashboard component:

ng generate component dashboard

Configure Component Template

Replace the content of the dashboard.component.html file to specify a place for a dashboard container:

<div class="dashboard-container" style="width: 100%;height: 100%;"> </div>

Configure Component Class

Replace the content of the dashboard.component.ts file with the code below to import the required decorators and modules and configure the Dashboard component:

import * as Globalize from 'globalize';
declare var require: (e: string) => object;

import { Component, AfterViewInit, ElementRef, OnDestroy } from '@angular/core';
import { DashboardControl, ResourceManager, DashboardPanelExtension } from 'devexpress-dashboard';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})

export class DashboardComponent implements AfterViewInit, OnDestroy {
  private dashboardControl!: DashboardControl;
  constructor(private element: ElementRef) {
    this.initGlobalize();
    ResourceManager.embedBundledResources();
  }
  initGlobalize() {
    Globalize.load([
      require('devextreme-cldr-data/en.json'),
      //require('devextreme-cldr-data/de.json'),
      require('devextreme-cldr-data/supplemental.json')
    ]);
    Globalize.locale('en');
  }
  ngAfterViewInit(): void {
    this.dashboardControl = new DashboardControl(this.element.nativeElement.querySelector(".dashboard-container"), {
      // Specifies a URL of the Web Dashboard's server.
      endpoint: "https://demos.devexpress.com/services/dashboard/api",
      workingMode: "Designer",
    });

    this.dashboardControl.render();
  }
  ngOnDestroy(): void {
    this.dashboardControl && this.dashboardControl.dispose();
  }
}

The DashboardControlOptions.endpoint property specifies the URL used to send data requests to a server. The value should consist of a base URL where the Web Dashboard's server side is hosted and a route prefix - a value that is set in the MVC / .NET Core MapDashboardRoute properties.

Add Global Styles

Add the following global styles in styles.css file:

@import url("../node_modules/jquery-ui/themes/base/all.css");  
@import url("../node_modules/devextreme/dist/css/dx.common.css");  
@import url("../node_modules/devextreme/dist/css/dx.light.css");  
@import url("../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css");  
@import url("../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.light.css");  
@import url("../node_modules/@devexpress/analytics-core/dist/css/dx-querybuilder.css");  
@import url("../node_modules/devexpress-dashboard/dist/css/dx-dashboard.light.css");  

Register Application Component

Insert the following code at the beginning of the app.component.html file to add a component reference:

<app-dashboard style="display: block;width:100%;height:800px;"></app-dashboard>
<!-- ... -->

Support Culture-Specific Data

Web Dashboard uses the globalize library to display culture-specific data.

Add the required cultures and specify one of the added locales in the Globalize.locale method to change the culture:

initGlobalize() {
  Globalize.load(
    require('devextreme-cldr-data/en.json'),
    require('devextreme-cldr-data/de.json'),
    require('devextreme-cldr-data/supplemental.json')
  );
  Globalize.locale('de');
}
Tip

See Localize Web Dashboard Control for information about UI localization.

Run the Application

Run the application.

ng serve --open

Open http://localhost:4200/ in your browser to see the result. The HTML JavaScript Dashboard displays the dashboard stored on the preconfigured server (https://demos.devexpress.com/services/dashboard/api).

See Also