Collecting data can be very useful for any project but making use of that data is more important. If figures and values are presented in a spreadsheet, for example, it can be difficult to tell what – if any – significant information it holds.
Victory is a library that can build charts in a declarative manner. It can respond to state changes and animate to show any new data. Unlike other libraries such as D3.js, it does not need direct control of the DOM.
In this tutorial, we will be creating a pie chart and a line chart using Victory. These will display the output for a simulated status dashboard.
To begin, make sure the tutorial files are downloaded and open up the tutorial directory on the command line. Then install the dependencies that we need from NPM, which includes React, Victory and a couple of other libraries to help format the data. Finally, start the development server.
> npm install
> npm start
The first component tracks the uptime of the application in a pie chart. This Uptime component gives a clear indication if the reliability falls below acceptable standards. Open the component at:
Each chart component supplied by Victory has sensible default values in case no other props are supplied to it. Each one is exported from the “victory” package we installed from NPM. Our first one – VictoryPie – will draw a simple monochrome pie chart along with some sample data. Add one to our Uptime component.
The pie chart is a comparison between uptime and downtime. Given the percentage of uptime is a value between 0 and 1, we can calculate the downtime by seeing what’s left over.
You can read upto 3 premium stories before you subscribe to Magzter GOLD
Log-in, if you are already a subscriber
Get unlimited access to thousands of curated premium stories and 5,000+ magazines
READ THE ENTIRE ISSUE