BarChart class
A bar chart widget that visualises categorical data as vertical bars.
Supply a dataset of DataItem objects and the chart will render each item as a bar whose height is proportional to its value.
Example:
BarChart(
title: 'Fruits',
dataset: [
DataItem(id: 0, label: 'Apples', value: 50),
DataItem(id: 1, label: 'Oranges', value: 30),
],
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- BarChart
Constructors
-
BarChart({Key? key, required List<
DataItem> dataset, String title = '', double? height, double? width, double maxWidth = 600.0, List<Color> customColors = colors, Color? backGroundColor, bool showTitle = true, bool showLabels = true, bool showLegend = false, bool showLines = true, bool animate = true, Duration animationDuration = const Duration(milliseconds: 900), Curve animationCurve = Curves.easeOutCubic, bool enableHover = true, ValueChanged<DataItem?> ? onBarHover, bool enableTapHighlight = true, bool toggleTapHighlight = true, dynamic onBarTap(DataItem) = _defaultOnTap, DatasetOrdering? datasetOrdering}) -
Creates a BarChart.
const
Properties
- animate → bool
-
Whether to animate the chart when it is first shown or rebuilt.
final
- animationCurve → Curve
-
Curve used by the entry animation.
final
- animationDuration → Duration
-
Duration of the entry animation.
final
- backGroundColor → Color?
-
Background color of the chart container.
final
-
customColors
→ List<
Color> -
Color palette used when a DataItem does not specify its own color.
final
-
dataset
→ List<
DataItem> -
The data items to display as bars.
final
- datasetOrdering → DatasetOrdering?
-
Optional ordering applied to dataset before rendering.
final
- enableHover → bool
-
Whether hovering with a mouse pointer highlights bars (desktop/web).
final
- enableTapHighlight → bool
-
Whether tapping a bar highlights it (useful on mobile where hover
doesn't exist).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
Fixed height for the chart widget.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- maxWidth → double
-
Maximum width the chart may occupy. Defaults to
600.0.final -
onBarHover
→ ValueChanged<
DataItem?> ? -
Callback invoked when the hovered bar changes (desktop/web).
final
- onBarTap → dynamic Function(DataItem)
-
Callback invoked when the user taps a bar.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showLabels → bool
-
Whether to render bar labels below each bar. Defaults to
true.final - showLegend → bool
-
Whether to render the legend below the chart. Defaults to
false.final - showLines → bool
-
Whether to render the horizontal grid lines. Defaults to
true.final - showTitle → bool
-
Whether to render the chart title. Defaults to
true.final - title → String
-
Optional title displayed at the top of the chart.
final
- toggleTapHighlight → bool
-
Whether tapping the already-highlighted bar clears the highlight.
final
- width → double?
-
Fixed width for the chart widget.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< BarChart> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited