Skip to main content

Bar Chart

The Bar Chart is a fundamental data visualization that uses rectangular bars to represent the values of different categories. The length of each bar is proportional to the value it represents. Bar charts are effective for comparing quantities across different categories.

Installation/Import

To use the Bar Chart component, import it from the @rexora/charts package:

tsx
import { BarChart } from '@rexora/charts';

Usage

Here's a basic example of how to render a Bar Chart:

tsx
import React from 'react';
import { BarChart } from '@rexora/charts';

const data = [
{ category: 'A', value: 30 },
{ category: 'B', value: 80 },
{ category: 'C', value: 45 },
{ category: 'D', value: 60 },
];

const MyBarChartComponent = () => {
return (
<div style={{ width: '100%', height: '300px' }}>
<BarChart data={data} />
</div>
);
};

export default MyBarChartComponent;

Props and Options

The BarChart component accepts the following props:

PropTypeDescriptionDefault
dataArray<object>An array of objects representing the data. Each object should have a category and a value property.[]
widthnumberThe width of the chart container.auto
heightnumberThe height of the chart container.auto
marginobjectMargins around the chart (top, right, bottom, left).{ top: 20, right: 20, bottom: 30, left: 40 }
colorstringThe color of the bars.steelblue
xAccessorstringThe key in the data object for the category axis.'category'
yAccessorstringThe key in the data object for the value axis.'value'
tooltipbooleanWhether to show tooltips on hover.true
xAxisLabelstringLabel for the x-axis.''
yAxisLabelstringLabel for the y-axis.''
......Additional D3-specific configuration options can be passed.

Note: More advanced customization options for scales, axes, and interactivity can be passed directly to the D3 rendering logic within the component implementation.