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.
Sample API call :
Fetching the data for the chart
Setting the URL to fetch data from, this URL will be used to make the AJAX call.
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.
Set the application state with the received data which the pie chart component will use as it’s data source.
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.
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.
Configuring color for each Cell in the pie so it looks more interactive and we have distinguished colors for all devices.
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.