bk-react-charts
The Chart component is used to visualize data with user interaction and provides customization options to visually configure the data. It can bind data from datasources such as JSON object array and web services. All of the chart elements are rendered using Scalable Vector Graphics (SVG).
Install
npm install --save bk-react-charts
Line-Chart
Following example shows the sales report with default line series in the chart.
Source
import React from 'react'import Chart from 'bk-react-charts'import 'bk-react-charts/dist/index.css' { let data = month: 'Jan' sales: 35 month: 'Feb' sales: 37 month: 'Mar' sales: 39 month: 'Apr' sales: 38 month: 'May' sales: 37 month: 'Jun' sales: 41 month: 'Jul' sales: 40 month: 'Aug' sales: 43 month: 'Sep' sales: 42 month: 'Oct' sales: 44 month: 'Nov' sales: 45 month: 'Dec' sales: 46 return <Chart ='400px' ='700px' = ='month' ='sales' /> }
Demo
Customized Line chart with multiple series
In following example, we have added multiple series of sales data using dataSource
property. Also you can customize axis, title and tooltips.
- Customize yAxis - You can customize the yAxis's interval, minimum, maximum, lineStyle and labelFormat using
primaryYAxis
. - Tooltip - You can enable or disable the tooltip using
tooltip
property.
Source
import React from 'react'import Chart from 'bk-react-charts'import 'bk-react-charts/dist/index.css' { let data = month: 'Jan' sales: 35 month: 'Feb' sales: 37 month: 'Mar' sales: 39 month: 'Apr' sales: 38 month: 'May' sales: 37 month: 'Jun' sales: 41 month: 'Jul' sales: 40 month: 'Aug' sales: 43 month: 'Sep' sales: 42 month: 'Oct' sales: 44 month: 'Nov' sales: 45 month: 'Dec' sales: 46 let data2 = month: 'Jan' sales: 45 month: 'Feb' sales: 47 month: 'Mar' sales: 46 month: 'Apr' sales: 48 month: 'May' sales: 46 month: 'Jun' sales: 49 month: 'Jul' sales: 48 month: 'Aug' sales: 52 month: 'Sep' sales: 54 month: 'Oct' sales: 53 month: 'Nov' sales: 54 month: 'Dec' sales: 55 let data3 = month: 'Jan' sales: 23 month: 'Feb' sales: 24 month: 'Mar' sales: 25 month: 'Apr' sales: 28 month: 'May' sales: 26 month: 'Jun' sales: 29 month: 'Jul' sales: 28 month: 'Aug' sales: 29 month: 'Sep' sales: 27 month: 'Oct' sales: 29 month: 'Nov' sales: 30 month: 'Dec' sales: 31 return <Chart ='400px' ='700px' = ='month' ='sales' ='Inflation - Consumer Price' = = /> }
Demo for Line-Chart
Pie-Chart
This sample demonstrates pie chart for monthly expense report.
Customization options
You can explode the particular part of pie-chart using following properties.
- pieChartRadius - Helps you customize the pie-chart radius
- pieChartExplode - Enables or disables the explosion feature of the pie-chart
- pieChartExplodeIndex - Specifies the explosion index of the pie-chart item
- pieChartExplodeOffset - Specifies the exploding offset of the pie-chart item
import React from 'react'import Chart from 'bk-react-charts'import 'bk-react-charts/dist/index.css' { let expenseDetails = item: 'savings' spending: '40%' item: 'food' spending: '20%' item: 'homeRent' spending: '15%' item: 'dress' spending: '5%' item: 'travel' spending: '10%' item: 'entertainment' spending: '10%' return <Chart ='400px' ='400px' ='1px' = ='item' ='spending' = ='10%' = = ='Expense details' = ='PieChart' /> }
Demo for Pie-Chart
Bar-Chart
This sample shows the Olympic medal count with default column series in the chart.
import React from 'react'import Chart from 'bk-react-charts'import 'bk-react-charts/dist/index.css' { let goldMedals = countryCode: 'USA' count: 46 countryCode: 'GBR' count: 27 countryCode: 'CHN' count: 26 let silverMedals = countryCode: 'USA' count: 37 countryCode: 'GBR' count: 23 countryCode: 'CHN' count: 18 let bronzeMedals = countryCode: 'USA' count: 38 countryCode: 'GBR' count: 17 countryCode: 'CHN' count: 26 return <Chart ='400px' ='600px' ='1px' = ='countryCode' ='count' = ='2016 Olympics Medal counts' = ='BarChart' /> }
Demo for Bar-Chart
Support
For support and queries, you can contact bk.techee@gmail.com
License
MIT © PS-Bala