Bar Chart
A bar chart is a data visualization where each category is represented by a rectangle, with the width of the rectangle being proportional to the values being plotted. Idea is to develop a bar chart in react-vis. React-vis is a charting library that provides chart components. In other words, the chart is composed of multiple sub-components like XYPlot, xAxis, yAxis.
Usage
1 . Import BarChart after installation
2 . Add data or URL to BarChart component.
Examples
Basic BarChart With X and Y Axis: Demo
Basic BarChart with Labels: Demo
Stacked BarChart With Legends: Demo
Grouped BarChart With Legends: Demo
Props
Note: External props are mostly derived from react-vis & K2. All external props are linked. You can click highlighted props to get more details from official sites.
Property | Type | Required | Default value | Description |
---|---|---|---|---|
data | BarChartData[] | yes | Data for the chart. | |
xyPlot | XYPlotProps | no | None | Customize XYPlot. Inherited from "react-vis". |
xAxis | boolean | XAxisProps | no | true | Enable or customize XAxis. Inherited from "react-vis". |
yAxis | boolean | YAxisProps | no | true | Enable or customize YAxis. Inherited from "react-vis". |
verticalGridLines | boolean | VerticalGridLinesProps | no | true | Enable or customize VerticalGridLines. Inherited from "react-vis". |
horizontalGridLines | boolean | HorizontalGridLinesProps | no | true | Enable or customize HorizontalGridLines. Inherited from "react-vis". |
barWidth | number | no | 0.3 | Inherited from "react-vis" BarSeries |
title | string | JSX.Element | no | None | Title of the chart. |
animate | boolean | no | true | Enable the animation. |
colors | {[theme-name: e.g "light" or "dark"] : string[] | GradientColor[] | no | { dark: ["#5579ae", "#e5c238", "#CF7373", "#85BE50"], light: ["#5579ae", "#e5c238", "#CF7373", "#85BE50"], } | Colors of visual in different theme modes |
label | boolean | LabelComponent | no | true | Enable or customize the labels(Note: Labels appear only in case of single series). |
tooltip | boolean | TooltipProps | no | true | Enable or customize the tooltip. |
legends | boolean | LegendsProps | no | false | Enable or customize the legends. |
onClick | onClick?: (event: { data: HorizontalBarSeriesPoint }) => void; | no | None | Callback for bar click. |
style | CSSProperties | no | None | Styles applied to the root element of chart. |
className | string | no | None | Class applied to the root element of chart. |
classes | Classes | no | None | Classes of chart. |
BarChart is wrapped with fetchData HoC, to perform data handling tasks, which adds support for some additional props.
Custom Types
BarChartData
Here is the format of the data accepted by BarChart.
HorizontalBarSeriesProps and HorizontalBarSeriesPoint are derived from react-vis
LabelComponent
This is a type of custom label component. You can create a custom label component by this.
HorizontalBarSeriesPoint is derived from react-vis
GradientColor
Type of GradientColor object.
Classes
Classes enable customization and styling of chart elements through their classes.
ClassName | Type | Required | Default value | Description |
---|---|---|---|---|
root | string | no | None | Applied to root element of chart. |
header | string | no | None | Applied to header of chart. |
title | string | no | None | Applied to title of chart. |
legends | string | no | None | Applied to legends of chart. |
tooltip | string | no | None | Applied to tooltip of chart. |
chart | string | no | None | Applied to svg component of chart. |
barSeries | string | no | None | Applied to bar series of chart. |
xAxis | string | no | None | Applied to x axis of chart. |
yAxis | string | no | None | Applied to y axis of chart. |
label | string | no | None | Applied to labels of chart. |
Please see Class Specificity for correctly defining it.