Back to Fl Chart

Line Chart

repo_files/documentations/line_chart.md

1.2.016.2 KB
Original Source

<a href="https://www.youtube.com/watch?v=F3wTxTdAFaU&list=PL1-_rCwRcnbNpvodmbt43O81wMUdBv8-a"></a>

How to use

dart
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 swapAnimationDuration and swapAnimationCurve properties, respectively.

LineChartData

PropNameDescriptiondefault value
lineBarsDatalist of LineChartBarData to show the chart's lines, they stack and can be drawn on top of each other[]
betweenBarsDatalist of BetweenBarsData to fill the area between 2 chart lines[]
titlesDatacheck the FlTitlesDataFlTitlesData()
extraLinesDataExtraLinesData object to hold drawing details of extra horizontal and vertical lines. Check ExtraLinesDataExtraLinesData()
lineTouchDataLineTouchData holds the touch interactivity detailsLineTouchData()
rangeAnnotationsshow range annotations behind the chart, check RangeAnnotationsRangeAnnotations()
showingTooltipIndicatorsshow the tooltip based on provided list of LineBarSpot, The point is that you need to disable touches to show these tooltips manually[]
gridDatacheck the FlGridDataFlGridData()
borderDatacheck the FlBorderDataFlBorderData()
minXgets minimum x of x axis, if null, value will read from the input lineBars (But it is more performant if you provide them)null
maxXgets maximum x of x axis, if null, value will read from the input lineBars (But it is more performant if you provide them)null
baselineXdefines the baseline of x-axis0
minYgets minimum y of y axis, if null, value will read from the input lineBars (But it is more performant if you provide them)null
maxYgets maximum y of y axis, if null, value will read from the input lineBars (But it is more performant if you provide them)null
baselineYdefines the baseline of y-axis0
clipDataclip the chart to the border (prevent drawing outside the border)FlClipData.none()
backgroundColora background color which is drawn behind th chartnull
rotationQuarterTurnsRotates the chart 90 degrees (clockwise) in every quarter turns. This feature works like the RotatedBox widget0

LineChartBarData

PropNameDescriptiondefault value
showdetermines to show or hide the bar linetrue
spotslist of FlSpot's x and y coordinates that the line go through it[]
colorcolor of the line[Colors.redAccent]
gradientYou can use any Gradient here. such as LinearGradient or RadialGradientnull
gradientAreadetermines the area where the gradient is appliednull
barWidthgets the stroke width of the line bar2.0
isCurvedcurves the corners of the line on the spot's positionsfalse
curveSmoothnesssmoothness radius of the curve corners (works when isCurved is true)0.35
preventCurveOverShootingprevent overshooting when draw curve line on linear sequence spots, check this issuefalse
preventCurveOvershootingThresholdthreshold for applying prevent overshooting algorithm10.0
isStrokeCapRounddetermines whether start and end of the bar line is Qubic or Roundfalse
isStrokeJoinRounddetermines whether stroke joins have a round shape or a sharp edgefalse
belowBarDatacheck the BarAreaDataBarAreaData
aboveBarDatacheck the BarAreaDataBarAreaData
dotDatacheck the FlDotDataFlDotData()
showingIndicatorsshow indicators based on provided indexes[]
dashArrayA circular array of dash offsets and lengths. For example, the array [5, 10] would result in dashes 5 pixels long followed by blank spaces 10 pixels long. The array [5, 10, 5] would result in a 5 pixel dash, a 10 pixel gap, a 5 pixel dash, a 5 pixel gap, a 10 pixel dash, etc.null
shadowIt drops a shadow behind your bar, see Shadow.Shadow()
isStepLineChartIf sets true, it draws the chart in Step Line Chart style, using lineChartStepData.false
lineChartStepDataHolds data for representing a Step Line Chart, and works only if [isStepChart] is true.LineChartStepData()
errorIndicatorDataHolds data for representing an error indicator (you see the error indicators if you provide the xError or yError in the FlSpot).ErrorIndicatorData()

LineChartStepData

PropNameDescriptiondefault value
stepDirectionDetermines the direction of each step, could be between 0.0 (forward), and 1.0 (backward)LineChartStepData.stepDirectionMiddle

BetweenBarsData

PropNameDescriptiondefault value
fromIndexindex of the first LineChartBarData inside LineChartData (zero-based index)required
toIndexindex of the second LineChartBarData inside LineChartData (zero-based index)required
colorcolor of the area[Colors.blueGrey]
gradientYou can use any Gradient here. such as LinearGradient or RadialGradientnull

BarAreaData

PropNameDescriptiondefault value
showdetermines to show or hide the below, or above bar areafalse
colorcolor of the below, or above bar area[Colors.blueGrey]
gradientYou can use any Gradient here. such as LinearGradient or RadialGradientnull
spotsLinedraw a line from each spot the the bottom, or top of the chartBarAreaSpotsLine()
cutOffYcut the drawing below or above area to this y value (set applyCutOffY true if you want to set it)null
applyCutOffYdetermines should or shouldn't apply cutOffY (scutOffY should be provided)false

BarAreaSpotsLine

PropNameDescriptiondefault value
showdetermines show or hide the below, or above spots linetrue
flLineStylea FlLine object that determines style of the line[Colors.blueGrey]
checkToShowSpotLinea function to determine whether to show or hide the below or above line on the given spotshowAllSpotsBelowLine
applyCutOffYDetermines to inherit the cutOff properties from its parent BarAreaDatatrue

FlDotData

PropNameDescriptiondefault value
showdetermines to show or hide the dotstrue
checkToShowDota function to determine whether to show or hide the dot on the given spotshowAllDots
getDotPaintera function to determine how the dot is drawn on the given spot_defaultGetDotPainter

LineTouchData (read about touch handling)

PropNameDescriptiondefault value
enableddetermines to enable or disable touch behaviorstrue
mouseCursorResolveryou can change the mouse cursor based on the provided FlTouchEvent and LineTouchResponseMouseCursor.defer
touchTooltipDataa LineTouchTooltipData, that determines how show the tooltip on top of touched spots (appearance of the showing tooltip bubble)LineTouchTooltipData
getTouchedSpotIndicatora callback that retrieves list of TouchedSpotIndicatorData by the given list of LineBarSpot for showing the indicators on touched spotsdefaultTouchedIndicators
touchSpotThresholdthe threshold of the touch accuracy10
distanceCalculatora function to calculate the distance between a spot and a touch event_xDistance
handleBuiltInTouchesset this true if you want the built in touch handling (show a tooltip bubble and an indicator on touched spots)true
getTouchLineStartcontrols where the line starts, default is bottom of the chartdefaultGetTouchLineStart
getTouchLineEndcontrols where the line ends, default is the touch pointdefaultGetTouchLineEnd
touchCallbacklisten to this callback to retrieve touch/pointer events and responses, it gives you a FlTouchEvent and LineTouchResponsenull
longPressDurationallows to customize the duration of the longPress gesture. If null, the duration of the longPressGesture is kLongPressTimeoutnull

LineTouchTooltipData

PropNameDescriptiondefault value
tooltipBorderborder of the tooltip bubbleBorderSide.none
tooltipBorderRadiusbackground corner radius of the tooltip bubbleBorderRadius.circular(4)
tooltipPaddingpadding of the tooltipEdgeInsets.symmetric(horizontal: 16, vertical: 8)
tooltipMarginmargin between the tooltip and the touched spot16
tooltipHorizontalAlignmenthorizontal alginment of tooltip relative to the spotFLHorizontalAlignment.center
tooltipHorizontalOffsethorizontal offset of tooltip0
maxContentWidthmaximum width of the tooltip (if a text row is wider than this, then the text breaks to a new line120
getTooltipItemsa callback that retrieve list of LineTooltipItem by the given list of LineBarSpotdefaultLineTooltipItem
fitInsideHorizontallyforces tooltip to horizontally shift inside the chart's bounding boxfalse
fitInsideVerticallyforces tooltip to vertically shift inside the chart's bounding boxfalse
showOnTopOfTheChartBoxAreaforces the tooltip container to top of the linefalse
getTooltipColora callback that retrieves the Color for each touched spots separately from the given LineBarSpot to set the background color of the tooltip bubbleColors.blueGrey.darken(15)

LineTooltipItem

PropNameDescriptiondefault value
texttext string of each row in the tooltip bubblenull
textStyleTextStyle of the showing text rownull
textAlignTextAlign of the showing text rowTextAlign.center
textDirectionTextDirection of the showing text rowTextDirection.ltr
childrenList<TextSpan> pass additional InlineSpan children for a more advance tooltipnull

TouchedSpotIndicatorData

PropNameDescriptiondefault value
indicatorBelowLinea FlLine to show the below line indicator on the touched spotnull
touchedSpotDotDataa FlDotData to show a dot indicator on the touched spotnull

LineBarSpot

PropNameDescriptiondefault value
barthe LineChartBarData that contains a spotnull
barIndexindex of the target LineChartBarData inside LineChartDatanull
spotIndexindex of the target FlSpot inside LineChartBarDatanull

TouchLineBarSpot

PropNameDescriptiondefault value
barthe LineChartBarData that contains a spotnull
barIndexindex of the target LineChartBarData inside LineChartDatanull
spotIndexindex of the target FlSpot inside LineChartBarDatanull
distancedistance to the touch eventnull

LineTouchResponse

PropNameDescriptiondefault value
touchLocationthe location of the touch event in the device pixels coordinatesrequired
touchChartCoordinatethe location of the touch event in the chart coordinatesrequired
lineBarSpotsa list of TouchLineBarSpotnull

ShowingTooltipIndicators

PropNameDescriptiondefault value
showingSpotsDetermines the spots that each tooltip should be shown.null

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