Thursday, January 7, 2016

How to use Analytics JavaScript (JS) API in a JavaScript Client

In this post I'm going to create a simple JavaScript Client and show you how to use WSO2 Data Analytics Server 3.0.0 JavaScript API within it.

You can download the WSO2 Data Analytics Server 3.0.0 from here.

Extract the downloaded wso2das-3.0.0.zip file and create a folder inside DAS_HOME/repository/deployment/server/webapps/, with the name analytics-client.

Inside the analytics-client, create a folder with the name js. We keep this folder to store the imported JavaScript files in our web app.

Copy the following files from DAS_HOME/repository/deployment/server/jaggeryapps/portal/js/ into the js folder you created earlier.
  • carbon-analytics.js  
  • jquery-1.10.2.js
Now create the index.html file with the following content inside the analytics-client folder.


 

  DAS JS Client
  
  

  

 
 
 

Analytics JS Client



Now, start the server. Go to DAS_HOME/bin and execute the command, ./wso2server.sh

To invoke your web app from the browser, give the following url.

https://localhost:9443/analytics-client/index.html

Since we have used console.log() to display JavaScript values, activate debugging in your browser with F12, and select "Console" in the debugger menu. 

You can try more JavaScript functions exposed in Analytics JS API referring to the Data Analytics Server documentation.

References :

[1] https://docs.wso2.com/display/DAS300/Analytics+JavaScript+%28JS%29+API
[2] http://www.w3schools.com/js/js_debugging.asp


No comments: