You are currently viewing Implementing a device wise usage section on the skill page

Implementing a device wise usage section on the skill page

SUSI Skill CMS showcases all the skills on the index page as skill cards and users can visit any skill page for any skill by clicking on any of these cards, skill pages for each skill hold some interesting metrics like rating, usage data, country wise usage data etc. But since SUSI runs on different devices so we need something to distribute and showcase how a skill is performing on each device so we implemented a pie chart for visualization of device wise usage data.

About the API

An API is developed at the server so from the client we call this API to fetch data from the server and plug this data into the chart we wish to render.

Endpoint :



Parameters :

  • model
  • group
  • language
  • skill

Sample API call :




 "skill_usage": [
     "count": 3,
     "device_type": "Others"
     "count": 39,
     "device_type": "Android"
     "count": 1,
     "device_type": "Web Client"
 "session": {"identity": {
   "type": "host",
   "name": "",
   "anonymous": true
 "skill_name": "news",
 "accepted": true,
 "message": "Device wise skill usage fetched"

Fetching the data for the chart

Setting the URL to fetch data from, this URL will be used to make the AJAX call.

let deviceUsageUrl = `${urls.API_URL}/cms/getSkillsByAuthor.json?author_email=${cookies.get('emailId')}`;
deviceUsageUrl = deviceUsageUrl + '?model=' + modelValue + '&group=' + this.groupValue + '&language=' + this.languageValue + '&skill=' +;


Make an ajax call to extract data from the response and call a function which saves the data to the application state, this data will later be used to render our chart we wish to render.

 url: deviceUsageUrl,
 success: function(data) {
   if (data.skill_usage) {
 error: function(e) {


Set the application state with the received data which the pie chart component will use as it’s data source.

saveDeviceUsageData = (device_usage_data = []) => {

Implementing the UI

We already have a card component for device usage section so we append our device wise usage section to this already present card. We fetch the data in the skillListing component and pass that data as props to the skill usage component so using data from the received props we render our pie chart.

Importing the needed components from recharts library.

import { Tooltip, Legend, PieChart, Pie, Sector, Cell } from 'recharts';


Rendering the Piechart component with appropriate props, the data props is the most important which is taken from the application state which we saved earlier.

<PieChart width={600} height={350}>
 <Legend wrapperStyle={{ position: 'relative' }} />


Configuring color for each Cell in the pie so it looks more interactive and we have distinguished colors for all devices.

{, index) => (
     ][index % 5]


Rendering the Pie only when data is available in props so we don’t end up rendering a blank chart which obviously won’t look good.

 this.props.device_usage_data !== [] ? (
 ): ''



  • Swizec Teller, Rendering a pie chart using react and d3, URL
  • Pie chart example from recharts, URL

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.