Skip to Content
Technical Articles
Author's profile photo Ashok siva kumar Easa

Add NativeScript UI Chart as external plugin to MDK Exte​nsion App

In this blog post, we will cover how we can use the Native script as an external plugin to a Mobile Development Kit. To achieve this, we will use the UI “nativescript-ui-chart” to display sales details.

I’ll show you how easy it is to add the native script as an external plugin to a Mobile Development Kit app with an extension control. you can use the existing NativeScript plugins like nativescript-geolocation, nativescript-nfc, nativescript-ui-chart etc.

By the time you’ve gone through these steps, you’ll have integrated native script donut chart from the SAP Cloud Platform SDK into your MDK app. First, you’ll see how to add the extension control in the editor. Next, you’ll define a customer list-detail which displays customer details. Finally, you’ll see how to create extension control and use “nativescript-ui-chart”.

Step 1: Register an Extension Control

In the editor, right-click the project folder, and select New | MDK Extension Control.


Provide the below information:

  • Control Name : SalesChart
  • Module : SalesChartModule
  • Control : SalesChartControl
  • Class : SalesChartClass


Click Next. you will not need any schema.


Click Finish to confirm. you will see below a file “SalesChart.extension” is generated based on the control name which was provided in the above step.



Step 2: Create: MDK List-Detail Project

Create MDK a project with List-Detail template


Provide the Project Name as ” NS_CustomerSales”


Provide service configurations as below, And click on check service to validate.

Name SampleServiceV2
Service URL select /destinations/mobileservices_cf destination
Application ID
Destination Name
Enable Offline Store Uncheck it


Select the “Customers” entity type and click on Next and finish.


Navigate to Pages Folder and Delete “”.


Create a new page with the name “Salesdetails” as shown in the below.

Navigate to Actions, Under Customer Folder open “NavToCustomers_Detail.action” and set PageToOpen property to New page( which was created in the earlier step.


Navigate to Rule folder, Create a new rule with name “SalesData.js





export default function SalesData(sectionProxy) {

	//The following currentCustomer will retrieve the current customer record
	const currentCustomer = sectionProxy.getPageProxy().binding.CustomerId;

        'SalesOrderHeaders', [],`$filter=CustomerId eq '${currentCustomer}'`).then(results => {
		return results.get("_array");

Navigate to and Scroll down to the Extension Properties, switch to Text mode and paste the following information:

  "SalesData": "/NS_CustomerSales/Rules/SalesData.js" 


Step 3: Implement Extension

Navigate to Extensions folder, create files & folders as per below.

In tsconfig.json file, copy and paste the following code.


In main-model.ts file, copy and paste the following code.

import { Observable } from 'tns-core-modules/data/observable';

export class oModel extends Observable {
    private list : any;
    constructor() {
   private initData() {
            [{ SalesOrderId: "4500001", Amount: 10 }]); // Dummy record
        this.list = this.get( "SalesOrderHeader" );
   private setSalesOrderHeader( SalesOrderId, Amount ){
   		this.list.push({ "SalesOrderId": SalesOrderId , "Amount" : Amount });
   private getSalesOrderHeader(){
   		return this.list;

In SalesChartControl.ts file, copy and paste the following code.

import * as app from 'tns-core-modules/application';
import { BaseObservable } from 'mdk-core/observables/BaseObservable';
import { Color } from 'tns-core-modules/color';
import { IControl } from 'mdk-core/controls/IControl';
import { Label } from "tns-core-modules/ui/label";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
import { oModel } from './main-model';
import { Page } from 'tns-core-modules/ui/page';
import { RadPieChart, DonutSeries, ChartSeriesSelectionMode } from 'nativescript-ui-chart';
import { ObservableArray } from "tns-core-modules/data/observable-array";

export class SalesChartClass extends IControl {
  private _model: any;
  private _observable: BaseObservable;
  private _targetLabel: any;
  private _StackLayout: any;
  private oRadPieChart: any;
  private oDonutSeries: any;
  private Selectionmode: any;
  private seriesArray: any;

  public initialize(props) {
	// Initiate saleorder Model    
    if(!this._model){ this._model = new oModel(); };

   // Stack Layout
    this._StackLayout = new StackLayout();
    this._StackLayout.backgroundColor = "#f2efe8";
   // Create Label
    this._targetLabel = new Label();
    this._targetLabel.text  = "No Sales Data";
    // Create Pie Chart using External plugin
    this.oRadPieChart = new RadPieChart();
    this.oRadPieChart.row = 0 ;
    this.oDonutSeries = new DonutSeries();
    this.oDonutSeries.seriesName = "myDonutSeries";
    this.Selectionmode = <ChartSeriesSelectionMode> 'None';
    this.oDonutSeries.selectionMode = this.Selectionmode;
    this.oDonutSeries.expandRadius = 0.4;  
    this.oDonutSeries.outerRadiusFactor = 0.6;
    this.oDonutSeries.innerRadiusFactor = 0.8;
    this.oDonutSeries.valueProperty = "Amount";
    this.oDonutSeries.showLabels = true;
    this.seriesArray = new ObservableArray();
	this.oRadPieChart.series = this.seriesArray;
    // Extension Properties
    let extProps = this.definition().data.ExtensionProperties;
	  if (extProps) {
    	  // Resolve SalesData
	      this.valueResolver().resolveValue(extProps.SalesData, this.context, true).then(function(SalesData){
			this._targetLabel.text  = "Sales Orders Revenue";
			this._targetLabel.textAlignment = "center";
			this._targetLabel.fontWeight = "bold";
			SalesData.forEach(result=> {
				 this._model.setSalesOrderHeader( result.SalesOrderId, result.NetAmount );
            this.oDonutSeries.items = this._model.getSalesOrderHeader();

  public view() {
      return this._StackLayout; // Return View

  public viewIsNative() {
    return true;
  // Abstract Method
   public observable() {
    if (!this._observable) {
      this._observable = new BaseObservable(this, this.definition(),;
    return this._observable;
  // Abstract Method
    public setValue(value: any, notify: boolean): Promise<any> {
       return Promise.resolve();
  public setContainer(container: IControl) {
    // do nothing


Step 4: MDK Deploy and Activate

Right-click the NS_CustomerSales MDK Application in the project explorer pane and select MDK Deploy and Activate.

Past below in Externals and click on Next. “Nativescript-ui-chart” which is the external plugin we use in this app


Confirm the destination name and application id match where you want to deploy.


Step 5: Create Your Branded MDK Client

create a branded client using MDK SDK. Follow steps 1 to 4 from this tutorial

Make sure your external “Nativescript-ui-chart” is also mentioned in your branding client


Step 6: Run the MDK Client( Android )

In this step, we will run the app on android device

Navigate to \Customer Sales\app\App_Resources\Android.

Make sure compile SDK version is “30”( Android SDK API level )


In terminal or command line window, navigate to the app name folder Customer Sales App in MDClient_SDKpath and use tns run android –device <device identifier> command to run the MDK client on android device.

Once, the above command gets successfully executed, you will see new MDK client up and running in the Android device.

Tap START to connect MDK client to SAP Cloud Platform and Enter the email address and password to login to SAP Cloud Platform and tap Log On to authenticate.

Upon finishing the authentication, Tap OK to update the client with new MDK metadata.

Navigate to the Customer List page and click on any of the customer to see the Nativescript Chart loading in the extension page



Make sure you have created enough mock data by clicking on “Generate Sample Sales orders” icon as shown in the below


This Concludes overview of adding the native script as an external plugin to a Mobile Development Kit app with an extension control.



Please leave your questions and comments. I look forward to seeing how you use external plugins as extension controls in the Mobile Development Kit!



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Hong Wei Ma
      Hong Wei Ma

      Really good MDK document.

      I have a issue with main-module.ts:

      import { Observable } from 'tns-core-modules/data/observable';

      with error:

      Cannot find module 'tns-core-modules/data/observable'.ts(2307)

      I check the tsconfig.json file, there is no problem.


      Author's profile photo Siddhesh Dingankar
      Siddhesh Dingankar

      Wow such a detailed blog! Thanks Ashok siva kumar Easa.

      I am new to MDK, would love to know more about it from you. Also please guide on how to get in-depth knowledge of MDK to make better apps.

      Thanks again!!