Skip to main content

Line Chart

How to use​

LineChart(
LineChartData(
// read about it in the LineChartData 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.

LineChartData​

lineBarsDataList<LineChartBarData>#defaultconst []

List of LineChartBarData to show the chart's lines, they stack and can be drawn on top of each other.

betweenBarsDataList<BetweenBarsData>#defaultconst []

Fills area between two LineChartBarData with a color or gradient.

titlesDataFlTitlesData#defaultconst FlTitlesData()

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

extraLinesDataExtraLinesData?#defaultconst ExtraLinesData()

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

lineTouchDataLineTouchData#defaultconst LineTouchData()

Handles touch behaviors and responses.

showingTooltipIndicatorsList<ShowingTooltipIndicators>#defaultconst []

You can show some tooltipIndicators (a popup with an information) on top of each LineChartBarData.spots using showingTooltipIndicators, just put line indicator number and spots 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 LineTouchData.handleBuiltInTouches.

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.

minXdouble?#

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

maxXdouble?#

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

baselineXdouble?#default0

The x value that the vertical grid lines and the titles are aligned to, they are drawn at every baselineX + n * interval.

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).

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).

baselineYdouble?#default0

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

clipDataFlClipData?#defaultconst FlClipData.none()

Clips the chart to its border (prevents drawing outside of the border), see FlClipData.

backgroundColorColor?#defaultColors.transparent

A background color which is drawn behind the chart.

rotationQuarterTurnsint#default0

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

LineChartBarData​

spotsList<FlSpot>#defaultconst []

This line goes through this spots.

You can have multiple lines by splitting them, put a FlSpot.nullSpot between each section.

showbool#defaulttrue

Determines to show or hide the line.

colorColor?#

If provided, this LineChartBarData draws with this color. Otherwise we use gradient to draw the line. 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 LineChartBarData draws with this gradient. Otherwise we use color to draw the line. It throws an exception if you provide both color and gradient.

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

gradientAreaLineChartGradientArea#defaultLineChartGradientArea.rectAroundTheLine

Only effective if gradient is provided.

It will be used to determine the area of the gradient.

barWidthdouble#default2.0

Determines thickness of drawing line.

isCurvedbool#defaultfalse

If it's true, LineChart draws the line with curved edges, otherwise it draws line with hard edges.

curveSmoothnessdouble#default0.35

If isCurved is true, it determines smoothness of the curved edges.

preventCurveOverShootingbool#defaultfalse

Prevents overshooting when drawing a curve line on linear sequence spots, check this issue.

preventCurveOvershootingThresholddouble#default10.0

Applies threshold for preventCurveOverShooting algorithm.

isStrokeCapRoundbool#defaultfalse

If true, the start and end of the line are round (StrokeCap.round), otherwise they are flat (StrokeCap.butt).

isStrokeJoinRoundbool#defaultfalse

If true, the corners of the line are round (StrokeJoin.round), otherwise they are sharp (StrokeJoin.miter).

belowBarDataBarAreaData?#defaultBarAreaData()

Fills the space below the line, using a color or gradient, see BarAreaData.

aboveBarDataBarAreaData?#defaultBarAreaData()

Fills the space above the line, using a color or gradient, see BarAreaData.

dotDataFlDotData#defaultconst FlDotData()

Responsible for showing spots on the line as dots, see FlDotData.

errorIndicatorDataFlErrorIndicatorData<LineChartSpotErrorRangeCallbackInput>#defaultconst FlErrorIndicatorData<LineChartSpotErrorRangeCallbackInput>()

Holds data for showing error indicators on the spots in this line (they are shown if you provide FlSpot.xError or FlSpot.yError).

showingIndicatorsList<int>#defaultconst []

Shows indicators (a thicker line and a larger dot) on the spots at the provided indices.

dashArrayList<int>?#defaultnull

Draws the line 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, and [5, 10, 5] results in a 5 pixel dash, a 10 pixel gap, a 5 pixel dash, a 5 pixel gap, a 10 pixel dash, etc.

shadowShadow#defaultconst Shadow(color: Colors.transparent)

Drops a Shadow behind the line.

isStepLineChartbool#defaultfalse

If sets true, it draws the chart in Step Line Chart style, using LineChartBarData.lineChartStepData.

lineChartStepDataLineChartStepData#defaultconst LineChartStepData()

Holds data for representing a Step Line Chart, and works only if isStepLineChart is true.

LineChartGradientArea​

rectAroundTheLine#

The gradient area will be around the line only, meaning the gradient will exactly wrap around the curve.

wholeChart#

The entire chart area will be used as the gradient area for the curve.

LineChartStepData​

stepDirectiondouble#defaultLineChartStepData.stepDirectionMiddle

Determines the direction of each step, between 0.0 (stepDirectionForward) and 1.0 (stepDirectionBackward).

BetweenBarsData​

fromIndexint#required

Index of the first LineChartBarData in LineChartData.lineBarsData (zero-based), the area is filled from this line.

toIndexint#required

Index of the second LineChartBarData in LineChartData.lineBarsData (zero-based), the area is filled up to this line.

colorColor?#

If provided, this BetweenBarsData fills the area with this color. Otherwise we use gradient to fill it. It throws an exception if you provide both color and gradient.

Defaults to a semi-transparent Colors.blueGrey if neither color nor gradient is provided.

gradientGradient?#defaultnull

If provided, this BetweenBarsData fills the area with this gradient. Otherwise we use color to fill it. It throws an exception if you provide both color and gradient.

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

BarAreaData​

showbool#defaultfalse

Determines whether to show or hide the below, or above bar area.

colorColor?#

If provided, this BarAreaData fills the area with this color. Otherwise we use gradient to fill it. It throws an exception if you provide both color and gradient.

Defaults to a semi-transparent Colors.blueGrey if neither color nor gradient is provided.

gradientGradient?#defaultnull

If provided, this BarAreaData fills the area with this gradient. Otherwise we use color to fill it. It throws an exception if you provide both color and gradient.

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

spotsLineBarAreaSpotsLine#defaultconst BarAreaSpotsLine()

Holds data for drawing a line from each spot to the bottom, or top of the chart, see BarAreaSpotsLine.

cutOffYdouble#default0

Cuts the drawing of the below or above area at this y value (set applyCutOffY to true to apply it).

applyCutOffYbool#defaultfalse

Determines whether to apply cutOffY.

BarAreaSpotsLine​

showbool#defaultfalse

Determines to show or hide all the lines.

flLineStyleFlLine#defaultconst FlLine()

Holds appearance of drawing line on the spots.

checkToShowSpotLinebool Function(FlSpot)#defaultshowAllSpotsBelowLine

Checks to show or hide lines on the spots.

applyCutOffYbool#defaulttrue

Determines to inherit the cutOff properties from its parent BarAreaData

FlDotData​

showbool#defaulttrue

Determines show or hide all dots.

checkToShowDotbool Function(FlSpot, LineChartBarData)#defaultshowAllDots

Checks to show or hide an individual dot.

getDotPainterFlDotPainter Function(FlSpot, double, LineChartBarData, int)#default_defaultGetDotPainter

Callback which is called to set the painter of the given FlSpot. The FlSpot is provided as parameter to this callback

LineTouchData (read about touch handling)​

enabledbool#defaulttrue

Determines whether to enable or disable touch behaviors.

touchCallbackvoid Function(FlTouchEvent, LineTouchResponse?)?#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, LineTouchResponse?)?#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).

touchTooltipDataLineTouchTooltipData#defaultconst LineTouchTooltipData()

Determines how the tooltip looks on top of the touched spots, see LineTouchTooltipData.

getTouchedSpotIndicatorList<TouchedSpotIndicatorData?> Function(LineChartBarData, List<int>)#defaultdefaultTouchedIndicators

Retrieves a list of TouchedSpotIndicatorData for the touched spots of a line, to show an indicator on each of them.

touchSpotThresholddouble#default10

Distance threshold to handle the touch event.

distanceCalculatordouble Function(Offset, Offset)#default_xDistance

Calculates the distance between a touch point and a spot, to find the closest spots to the touch. By default, only the horizontal distance is used.

handleBuiltInTouchesbool#defaulttrue

If true, the chart handles touches by itself: it shows a tooltip bubble and an indicator on the touched spots.

getTouchLineStartdouble Function(LineChartBarData, int)#defaultdefaultGetTouchLineStart

The starting point on y axis of the touch line. By default, line starts on the bottom of the chart.

getTouchLineEnddouble Function(LineChartBarData, int)#defaultdefaultGetTouchLineEnd

The end point on y axis of the touch line. By default, line ends at the touched point. If line end is overlap with the dot, it will be automatically adjusted to the edge of the dot.

LineTouchTooltipData​

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 spot.

tooltipHorizontalAlignmentFLHorizontalAlignment#defaultFLHorizontalAlignment.center

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

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.

getTooltipItemsList<LineTooltipItem?> Function(List<LineBarSpot>)#defaultdefaultLineTooltipItem

Retrieves a LineTooltipItem for each touched spot, to show as a row inside the tooltip.

getTooltipColorColor Function(LineBarSpot)#defaultdefaultLineTooltipColor

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

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.

showOnTopOfTheChartBoxAreabool#defaultfalse

Forces the tooltip container to the top of the chart's box area, instead of on top of the touched spots.

rotateAngledouble#default0.0

Controls the rotation of the tooltip.

tooltipBorderBorderSide#defaultBorderSide.none

Border of the tooltip bubble.

LineTooltipItem​

textString#required

Text of this row in the tooltip bubble.

textStyleTextStyle#required

TextStyle of the text.

textAlignTextAlign#defaultTextAlign.center

TextAlign of the text.

textDirectionTextDirection#defaultTextDirection.ltr

TextDirection of the text.

childrenList<TextSpan>?#defaultnull

Additional TextSpans after text, for a more advanced tooltip.

TouchedSpotIndicatorData​

indicatorBelowLineFlLine#required

The line drawn below the touched spot, see FlLine.

touchedSpotDotDataFlDotData#required

The dot drawn on the touched spot, see FlDotData.

LineBarSpot​

Also has the properties of FlSpot.

barLineChartBarData#

Is the LineChartBarData that this spot is inside of.

barIndexint#

Is the index of our bar, in the LineChartData.lineBarsData list.

spotIndexint#

Is the index of this spot, in the LineChartBarData.spots list.

TouchLineBarSpot​

Also has the properties of LineBarSpot.

distancedouble#

Distance in pixels from where the user tapped.

LineTouchResponse​

touchLocationOffset#

The location of the touch in pixels on the screen.

touchChartCoordinateOffset#

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

lineBarSpotsList<TouchLineBarSpot>?#

touch happened on these spots (if a single line provided on the chart, lineBarSpots's length will be 1 always)

ShowingTooltipIndicators​

showingSpotsList<LineBarSpot>#required

Determines the spots that each tooltip should be shown.

some samples​


Sample 1 (Source Code)​
Sample 2 (Source Code)​
Sample 3 (Source Code)​
Sample 4 (Source Code)​
Sample 5 (Source Code)​
Sample 6 - Reversed (Source Code)​
Sample 7 (Source Code)​
Sample 8 (Source Code)​
Sample 9 (Source Code)​
Sample 10 (Source Code)​
Sample 11 (Source Code)​

https://user-images.githubusercontent.com/7009300/152555425-3b53ac8c-257f-49b0-8d75-1a878c03ccaa.mp4