Horizontal chart
All necessary information about basic horizontal chart
General information
Horizontal chart is one of the simplest chart in the surf-charts
library, designed to display a small amount of simple structured information in the form of horizontal columns with field names on the left side of them and values expressed in row size and tooltip inscriptions, chart also has values line at the bottom.
Example of a vertical chart
The example below shows the default behavior of the chart with only the necessary props.
import { HorizontalChart } from '@surf/charts';
const data = [
{ label: 'January', value: 1200 },
{ label: 'February', value: 800 },
{ label: 'March', value: 1500 },
{ label: 'April', value: 1100 },
{ label: 'May', value: 1400 }
];
function App() {
return <HorizontalChart label='Sales' data={data} />;
}
Result
- January
- February
- March
- April
- May
Handling dynamic data
Charts often need to handle dynamic data, such as when data is fetched from a server. The HorizontalChart
component is designed to handle various data scenarios gracefully:
- Incomplete Data: If the number of data points is less than the
maxBars
, only the available data will be displayed without leaving empty spaces. - Excess Data: If there are more data points than the specified
maxBars
, only the first few data points will be displayed according to themaxBars
value.
For full information about async data you can read here.
Customization
The HorizontalChart
component provides a certain number of props for customization. The properties are given in table below.
Clarification
It's worth considering that none of the props are contradictory, you can pass all props, or define only mandatory ones.
Props
Prop | Type | Default |
---|---|---|
className | string | - |
colorScheme | light | dark | dark |
maxBars | NumericRange<3, 15> | 5 |
label | string | - |
tooltipPostfix | string | - |
noDataContent | ReactNode | No data provided |
noLabelContent | ReactNode | No label |
styling | DerivedBarStyling | - |
sort | 'asc' | 'desc | - |
data | DerivedBarChartData | - |
props | ComponentProps<'div'> | - |
Last updated on 9/13/2024