Skip to Content
πŸŽ‰ Coral x Panda has been released πŸŽ‰ Read the Migration Guide

CoralBarChart

Basic Usage

import { CoralBarChart } from '@krakentech/coral-charts'; <CoralBarChart data={[ { x: '00', y: 1000, }, { x: '01', y: 500, }, ... ]} />
01,0002,0003,0004,00023

Horizontal

<CoralBarChart data={basicTemplateData} modifiers={{ height: 520, chart: { domainPadding: { y: [0, 10], x: [16, 10] }, }, bar: { horizontal: true, }, xAxis: { axisLabelPadding: 35, }, }} />
0001020304050607080910111213141516171819202122234,000

Default modifiers

BarChart has the following additional modifiers set by default

modifiers: { chart: { domainPadding: { x: [20, 10] }, } }

Full API

NameTypeDefault
modifiersChartModifiers & { bar?: BarDefinition; }
chartDescriptionReactNode

The description of the chart, which will be read by screen readers. This should be a short description of the chart’s purpose or content, as well as any relevant data points.

events.onClick(props: any) => void

Callback fired when the user clicks on a chart element.

  • props The properties of the clicked chart element.
events.onMouseOver(props: any) => void

Callback fired when the user hovers over a chart element.

  • props The properties of the hovered chart element.
events.onMouseOut(props: any) => void

Callback fired when the user stops hovering over a chart element.

  • props The properties of the chart element that was hovered over.
dataChartData[]
xsBarChartModifiers
smBarChartModifiers
mdBarChartModifiers
lgBarChartModifiers
xlBarChartModifiers

modifiers API

NameTypeDefault
heightnumber
legend.showLegendboolean

Should the legend show?

false
legend.renderedWidthnumber

When horizontalPosition is set to center or right, renderedWidth must be defined to ensure that the legend is correctly positioned.

legend.horizontalPosition"center" | "right" | "left"

The position of the legend on the horizontal axis.

legend.verticalPosition"top" | "bottom"

Set whether the legend be positioned above or below the chart.

legend.verticalPositionAdjustmentnumber

When assigning verticalPosition to bottom this prop allows granular control of the offset of the legend to the bottom of the chart.

legend.legendDatareadonly any[] | undefined

The series data to be displayed in the legend.

legend.legendColorScaleColorScalePropType

The color scale to be used for the legend. This will be mapped to the series data.

legend.itemsPerRownumber

Define how many items to show per row on the legend, the default will run all series on one line without wrapping them.

legend.dataComponentReact.ReactElement

Provide a custom series data icon, rather than the default coloured square.

yAxis.orientation"right" | "left"

Set the position of the y-axis to the left or right of the chart.

left
yAxis.axisLabelstring

Provides a label for the y-axis.

yAxis.axisLabelPaddingnumber

Provide offset padding to the axis label from the y-axis line.

yAxis.tickFormatany[] | ((tick: any, index: number, ticks: any[]) => string | number) | undefined

Specify how tick values should be formatted. This is likely to be function that takes a value and returns a formatted string, i.e. tickFormat={(x) => {}}.

yAxis.domain[number, number]

Manually specify the range of data the chart will include, given as an array of the minimum and maximum expected values. This will override the default domain calculation which works out the minimum and maximum values from the supplied data. If you pass a minimum or maximum value that is more or less than the minimum or maximum value in the data, the chart will still include the minimum or maximum value from the data.

xAxis.orientation"top" | "bottom"

Set the position of the x-axis to the top or bottom of the chart.

top
xAxis.fixTickLabelOverlapboolean

Dynamically adjust how many ticks show to prevent collision of ticks.

xAxis.axisLabelstring

Provides a label for the x-axis.

xAxis.axisLabelPaddingnumber

Provide offset padding to the axis label from the x-axis line.

xAxis.tickCountnumber

Define approximately how many ticks to show on the x-axis. Prioritizes returning β€œnice” values and evenly spaced ticks over an exact number of ticks.

xAxis.tickFormatany[] | ((tick: any, index: number, ticks: any[]) => string | number) | undefined

Specify how tick values should be formatted. This is likely to be function that takes a value and returns a formatted string, i.e. tickFormat={(x) => {}}.

xAxis.tickPaddingnumber

Specify how many pixels apart the ticks should be spaced..

xAxis.tickAnglenumber

Specify an angle that the ticks should be rotated to.

0
xAxis.textAnchor"start" | "middle" | "end" | "inherit"

Specify the point within the text that should align with the x-coordinate of the label’s position.

xAxis.domain[number, number]

Manually specify the range of data the chart will include, given as an array of the minimum and maximum expected values. Note you should only attempt to apply this property if your independent domain is numeric.

xAxis.offsetYnumber

Manually specify how far from the edge of its calculated position an axis should be offset in the y direction.

chart.domainPaddingForAxes<PaddingType>

Specify a number of pixels of padding to add to the beginning or end of a domain. This prop is useful for explicitly spacing data elements farther from the beginning or end of a domain to prevent axis crowding.

https://formidable.com/open-source/victory/docs/common-props#domainpaddingΒ 

chart.paddingPaddingProps

Amount of padding in number of pixels between the edge of the chart and any rendered child components

https://formidable.com/open-source/victory/docs/common-props#paddingΒ 

tooltip.showTooltipsboolean

Should the tooltip be shown on hover?

true
tooltip.labelFormatstring[] | number[] | ((data: any) => string | number | string[] | number[] | null) | undefined

Specify how labels values should be formatted. This is likely to be function that takes a value and returns a formatted string, i.e. ({ datum }) => {}.

bar.horizontalboolean

Switch the axes so the chart runs horizontally rather than vertically.

bar.barRationumber

Specify approximate ratio between bar width and bar spacing. If width is not specified, this will calculate a default width for each bar given total number of bars and width of chart.

bar.barWidthnumber

Specify the width of each bar. When not specified, a default value will be calculated based on the total number of bars and width of chart.

bar.cornerRadiusNumberOrCallback | Partial<Record<VictoryBarCornerRadiusKey, NumberOrCallback>> | undefined

Specify the radius of each bar. When not specified, a default value will be applied to the top of each bar.

bar.fillColourstring

Supply an override for the default fill colour of the area.

bar.customFlyoutElement

Provide a custom flyout to be rendered on hover.

Last updated on