Bar Chart
The BarChart React component displays grouped or stacked bar charts for easy comparison of categorical data. Fully customizable and responsive, it supports tooltips, animations, and various layout options.
The BarChart component is used to visualize data in a bar chart format. It is a wrapper around the Recharts BarChart component.
Usage
import { BarChart } from "@sparrowengg/twigs-charts";
const Chart = () => {
return (
<BarChart
data={[
{
name: "Page A",
UV: 4000,
PV: 2400,
AMT: 2400,
},
{
name: "Page B",
UV: 3000,
PV: 1398,
AMT: 2210,
},
{
name: "Page C",
UV: 2000,
PV: 9800,
AMT: 2290,
},
]}
dataKey="name"
series={[
{
name: "UV",
color: "#51D3D9",
},
{
name: "PV",
color: "#FEA58E",
},
{
name: "AMT",
color: "#BDA9EA",
},
]}
/>
);
};
The series
object determines the order of the bars in the chart. The first item in the array will be the first bar, the second item will be the second bar, and so on. Additional properties like color
, label
, yAxisId
, fill
, stroke
, unit
, stackId
, valueFormatter
are optional and can be used to customize the bars.
Props
Prop | Type | Default |
---|---|---|
chartProps? | - | |
barProps? | - | |
maxBarWidth? | number | - |
orientation? | 'horizontal' | 'vertical' | 'horizontal' |
barLabelProps? | SVGTextElementAttributes<SVGTextElement> | - |
showBarLabel? | boolean | false |
type? | 'default' | 'stacked' | 'default' |
showTooltipFooter? | boolean | - |
highlightOnLegendHover? | boolean | true |
valueFormatter? | Function | - |
containerProps? | HTMLDivElementAttributes | - |
cartesianGridProps? | - | |
rightYAxisProps? | - | |
showRightYAxis? | boolean | false |
yAxisLabel? | string | - |
xAxisLabel? | string | - |
yAxisProps? | - | |
xAxisProps? | - | |
showTooltip? | boolean | true |
showLegend? | boolean | false |
unit? | string | - |
height? | string | number | 300 |
width? | string | number | 100% |
dataKey | string | - |
series | ChartSeries[] | - |
data | Array<Object> | [] |
Examples
Multi data
Stacked
Stacked charts are useful when you want to compare multiple data points within a single bar. You can set type="stacked"
to enable this.
With Legend
Legend is a useful way to add labels to the bars. You can set showLegend
to true
to enable this.
Two Y-axis
Two Y-axis are useful when you want to compare two different data points within a single bar. You can set showRightYAxis
to true
to enable this. Additionally yAxisId
should be added to the series object, accepted values are left
and right
.
With Label and Unit
Labels can be enabled by setting showBarLabel
to true
. Unit can be added by setting unit
to the series object.
With valueFormatter
valueFormatter
can be used to format the values in the chart. It accepts a function that takes the value and returns a string.
With custom labels
label
property can be passed to the series object to add custom labels to the bars.
Area Chart
The AreaChart React component renders customizable, responsive area charts for visualizing data trends over time. Ideal for dashboards and analytics apps, it supports tooltips, gradients, and animations for enhanced data presentation.
Composite Chart
The CompositeChart React component combines multiple chart types—line, area, and bar—into a single, interactive visualization. Ideal for complex data comparisons, it offers full customization and responsive design.