Skip to main content

Bar Chart

How to use​

BarChart(
BarChartData(
// read about it in the BarChartData section
),
duration: Duration(milliseconds: 150), // Optional
curve: Curves.linear, // Optional
);

Implicit Animations​

When you change the chart's state, it animates to the new state internally (using implicit animations). You can control the animation duration and curve using optional duration and curve properties, respectively.

BarChartData​

barGroupsList<BarChartGroupData>?#defaultconst []

BarChart draws barGroups that each of them contains a list of BarChartRodData.

groupsSpacedouble?#default16

Apply space between the barGroups.

It is used only when alignment is BarChartAlignment.start, BarChartAlignment.center or BarChartAlignment.end (the other alignments spread the groups in the free space).

alignmentBarChartAlignment?#defaultBarChartAlignment.spaceEvenly

Arrange the barGroups, see BarChartAlignment.

titlesDataFlTitlesData?#defaultconst FlTitlesData(topTitles: AxisTitles())

Holds data to draw the titles around the chart, see FlTitlesData.

barTouchDataBarTouchData?#defaultconst BarTouchData()

Handles touch behaviors and responses.

maxYdouble?#

Maximum y value of the chart. If you don't provide it, it is calculated from the chart's data (providing it is more performant).

minYdouble?#

Minimum y value of the chart. If you don't provide it, it is calculated from the chart's data (providing it is more performant).

baselineYdouble?#default0

The y value that the horizontal grid lines and the titles are aligned to, they are drawn at every baselineY + n * interval.

gridDataFlGridData?#defaultconst FlGridData()

Holds data to draw the grid lines behind the chart, see FlGridData.

borderDataFlBorderData?#defaultFlBorderData()

Holds data to draw the border around the chart, see FlBorderData.

rangeAnnotationsRangeAnnotations?#defaultconst RangeAnnotations()

Highlights some horizontal or vertical ranges behind the chart, see RangeAnnotations.

backgroundColorColor?#defaultColors.transparent

A background color which is drawn behind the chart.

extraLinesDataExtraLinesData?#defaultconst ExtraLinesData()

Extra horizontal or vertical lines to draw on the chart, see ExtraLinesData (the bar chart only draws the horizontal ones).

rotationQuarterTurnsint#default0

Rotates the chart 90 degrees (clockwise) in every quarter turn. It works like the RotatedBox widget.

errorIndicatorDataFlErrorIndicatorData<BarChartSpotErrorRangeCallbackInput>#defaultconst FlErrorIndicatorData()

Holds data for showing error (threshold) indicators on the spots in the different BarChartGroupData.barRods

BarChartGroupData​

xint#required

Order along the x axis in which titles, and titles only, will be shown.

Note x does not reorder bars from barRods; instead, it gets the title in x position through SideTitles.getTitlesWidget function.

groupVerticallybool?#defaultfalse

If set true, it will show bars below/above each other. Otherwise, it will show bars beside each other.

barRodsList<BarChartRodData>?#defaultconst []

BarChart renders barRods that represents a rod (or a bar) in the bar chart.

barsSpacedouble?#default2

BarChart applies barsSpace between barRods if groupVertically is false.

showingTooltipIndicatorsList<int>?#defaultconst []

you can show some tooltipIndicators (a popup with an information) on top of each BarChartRodData using showingTooltipIndicators, just put indices you want to show it on top of them.

An important point is that you have to disable the default touch behaviour to show the tooltip manually, see BarTouchData.handleBuiltInTouches.

BarChartAlignment​

start#

Places the groups at the start of the chart.

end#

Places the groups at the end of the chart.

center#

Places the groups in the middle of the chart.

spaceEvenly#

Places the free space evenly between the groups, and before the first and after the last one.

spaceAround#

Places the free space evenly between the groups, and half of it before the first and after the last one.

spaceBetween#

Places the free space evenly between the groups, and none before the first and after the last one.

BarChartRodData​

fromYdouble?#default0

BarChart renders rods vertically from fromY.

toYdouble#required

BarChart renders rods vertically from fromY to toY.

toYErrorRangeFlErrorRange?#defaultnull

If the data has error range/threshold, it will be rendered with this error range. So you can provide the FlErrorRange.lowerBy and FlErrorRange.upperBy that is relative to the toY property.

If you want to customize the visual representation of the error range, you can use BarChartData.errorIndicatorData to customize the error range

colorColor?#

If provided, this BarChartRodData draws with this color. Otherwise we use gradient to draw the rod. It throws an exception if you provide both color and gradient.

Defaults to Colors.cyan if neither color nor gradient is provided.

gradientGradient?#defaultnull

If provided, this BarChartRodData draws with this gradient. Otherwise we use color to draw the rod. It throws an exception if you provide both color and gradient.

You can use any Gradient here, such as LinearGradient or RadialGradient.

widthdouble?#default8

The width of the rod.

borderRadiusBorderRadius?#defaultnull

The rounding of the corners of the rod. When null, the rod is fully rounded (with a radius of half of its width).

borderDashArrayList<int>?#defaultnull

Draws the borderSide dashed, it's a circular array of dash lengths and gaps. For example, [5, 10] results in dashes 5 pixels long followed by gaps 10 pixels long.

borderSideBorderSide?#

The border stroke around the rod, see BorderSide.

When null, the rod has no border (a BorderSide with a width of 0). The width of the border is capped to half of the rod's width.

backDrawRodDataBackgroundBarChartRodData?#defaultBackgroundBarChartRodData()

If you want to have a bar drawn in rear of this rod, use backDrawRodData, it uses to have a bar with a passive color in rear of the rod, for example you can use it as the maximum value place holder.

rodStackItemsList<BarChartRodStackItem>?#defaultconst []

If you are a fan of stacked charts (If you don't know what is it, google it), you can fill up the rodStackItems to have a Stacked Chart.

labelBarChartRodLabel#defaultconst BarChartRodLabel(show: false)

Optional label to display near the rod tip.

BackgroundBarChartRodData​

fromYdouble?#default0

fromY is where background starts to show

toYdouble?#default0

background starts to show from fromY to toY

showbool?#defaultfalse

Determines to show or hide this

colorColor?#

If provided, the background rod draws with this color. Otherwise we use gradient to draw it. It throws an exception if you provide both color and gradient.

Defaults to Colors.blueGrey if neither color nor gradient is provided.

gradientGradient?#defaultnull

If provided, the background rod draws with this gradient. Otherwise we use color to draw it. It throws an exception if you provide both color and gradient.

BarChartRodStackItem​

fromYdouble#required

Renders a Stacked Chart section from fromY

toYdouble#required

Renders a Stacked Chart section to toY

colorColor?#required

Renders a Stacked Chart section with color

gradientGradient?#defaultnull

Renders a Stacked Chart section with gradient

labelString?#defaultnull

An optional text label of the stack item.

labelStyleTextStyle?#defaultnull

The TextStyle of the label.

borderSideBorderSide#defaultUtils.defaultBorderSide

Renders border stroke for a Stacked Chart section

BarChartRodLabel​

Extends FlLabel.

showbool#defaulttrue

Whether the label is visible.

textString#default''

The text content of the label.

styleTextStyle?#defaultnull

The text style of the label.

When null (or when its inherit is true), it is merged with the ambient DefaultTextStyle, and it respects the bold text setting of the platform.

angledouble#default0

Rotation angle of the label in degrees.

textDirectionTextDirection#defaultTextDirection.ltr

Text direction of the label.

offsetOffset#defaultconst Offset(0, 8)

Offset from the rod tip to position the label. Offset.dx shifts horizontally, Offset.dy shifts vertically.

BarTouchData (read about touch handling)​

enabledbool?#defaulttrue

Determines whether to enable or disable touch behaviors.

touchCallbackvoid Function(FlTouchEvent, BarTouchResponse?)?#defaultnull

touchCallback notifies you about the happened touch/pointer events. It gives you a FlTouchEvent which is the happened event such as FlPointerHoverEvent, FlTapUpEvent, ... It also gives you a BaseTouchResponse which is the chart specific type and contains information about the elements that has touched.

mouseCursorResolverMouseCursor Function(FlTouchEvent, BarTouchResponse?)?#defaultnull

Using mouseCursorResolver you can change the mouse cursor based on the provided FlTouchEvent and BaseTouchResponse

longPressDurationDuration?#defaultnull

This property that allows to customize the duration of the longPress gesture. If null, it uses kLongPressTimeout (500 milliseconds).

touchTooltipDataBarTouchTooltipData?#defaultconst BarTouchTooltipData()

Determines how the tooltip looks on top of the touched rods, see BarTouchTooltipData.

touchExtraThresholdEdgeInsets?#defaultconst EdgeInsets.all(4)

Extends the touchable area of each rod by these insets.

allowTouchBarBackDrawbool?#defaultfalse

If true, touching the background rod (BarChartRodData.backDrawRodData) counts as touching the rod.

handleBuiltInTouchesbool?#defaulttrue

If true, the chart handles touches by itself: it shows a tooltip bubble on top of the touched rod.

BarTouchTooltipData​

tooltipBorderRadiusBorderRadius?#defaultBorderRadius.circular(4)

Sets a rounded radius for the tooltip.

tooltipPaddingEdgeInsets?#defaultconst EdgeInsets.symmetric(horizontal: 16, vertical: 8)

Applies a padding for showing contents inside the tooltip.

tooltipMargindouble?#default16

Margin between the tooltip and the touched rod.

tooltipHorizontalAlignmentFLHorizontalAlignment?#defaultFLHorizontalAlignment.center

Controls showing tooltip on left side, right side or center aligned with rod.

tooltipHorizontalOffsetdouble?#default0

Applies horizontal offset for showing tooltip.

maxContentWidthdouble?#default120

Maximum width of the tooltip's content, a text row which is wider than this breaks into a new line.

getTooltipItemBarTooltipItem? Function(BarChartGroupData, int, BarChartRodData, int)?#defaultdefaultBarTooltipItem

Retrieves data for showing content inside the tooltip.

getTooltipColorColor Function(BarChartGroupData)?#defaultdefaultBarTooltipColor

Retrieves the background color of the tooltip for each touched rod.

fitInsideHorizontallybool?#defaultfalse

Forces the tooltip to shift horizontally inside the chart, if overflow happens.

fitInsideVerticallybool?#defaultfalse

Forces the tooltip to shift vertically inside the chart, if overflow happens.

directionTooltipDirection?#defaultTooltipDirection.auto

Controls showing tooltip on top or bottom, default is auto.

rotateAngledouble?#default0.0

Controls the rotation of the tooltip (in degrees)

tooltipBorderBorderSide?#defaultBorderSide.none

Border of the tooltip bubble.

BarTooltipItem​

textString#required

Text of the content.

textStyleTextStyle#required

TextStyle of the showing content.

textAlignTextAlign#defaultTextAlign.center

TextAlign of the showing content.

textDirectionTextDirection#defaultTextDirection.ltr

Direction of showing text.

childrenList<TextSpan>?#defaultnull

Add further style and format to the text of the tooltip

BarTouchResponse​

touchLocationOffset#

The location of the touch in pixels on the screen.

touchChartCoordinateOffset#

The axis coordinate of the touch in chart's coordinate system.

spotBarTouchedSpot?#

Gives information about the touched spot

BarTouchedSpot​

Also has the properties of TouchedSpot.

touchedBarGroupBarChartGroupData#

The BarChartGroupData of the touched rod.

touchedBarGroupIndexint#

The index of touchedBarGroup in BarChartData.barGroups.

touchedRodDataBarChartRodData#

The touched BarChartRodData.

touchedRodDataIndexint#

The index of touchedRodData in BarChartGroupData.barRods.

touchedStackItemBarChartRodStackItem?#

The touched BarChartRodStackItem (in a stacked bar chart), null if no stack item is touched.

touchedStackItemIndexint#

The index of touchedStackItem in BarChartRodData.rodStackItems, -1 if no stack item is touched.

Some Samples​


Sample 1 (Source Code)​
Sample 2 (Source Code)​
Sample 3 (Source Code)​
Sample 4 (Source Code)​
Sample 5 (Source Code)​
Sample 6 (Source Code)​
Sample 7 (Source Code)​
Gist - Toggleable Tooltip (Source Code)​

https://user-images.githubusercontent.com/7009300/156784816-53f95dd9-f387-4600-8a92-d05b1aeea3da.mov