Hosts
A host is the top-level composable function or view for a chart. Hosts act as entry points—they accept implementations or subclasses of Chart
, ChartEntryModel
or ChartModelProducer
, and AxisRenderer
, among other things. They also house options related to scrolling, zooming, and other Chart
-independent matters.
Notably, a host accepts an instance of HorizontalLayout
, which lets you switch between a segmented style and a full-width one. You can also override the x step, which is the difference between the x values of neighboring major entries and defaults to the GCD of all the x values. For charts with dynamic data, placeholders can be added. These are shown when no ChartEntryModel
is available.
For Jetpack Compose, the host is the Chart
composable function. It is interacted with via its parameters. In the view system, there are two hosts—ChartView
and ComposedChartView
—both of which extend BaseChartView
. They are interacted with via their public members and XML attributes.
Across this wiki, in the context of the view system, we’ll be mentioning fields and functions of BaseChartView
, so keep in mind that you can access all those fields and functions via ChartView
and ComposedChartView
.
XML attributes
Views
BaseChartView
axisStyle
(Axis
): the style of all chart axes*AxisStyle
(Axis
): the style of a specific chart axiscolumnChartStyle
(ColumnChartStyle
): the style of column chartslineChartStyle
(LineChartStyle
): the style of line chartsshow*Axis
(boolean): whether to show a specific axischartHorizontalScrollingEnabled
(boolean): whether to enable horizontal scrollingchartZoomEnabled
(boolean): whether to enable zoomingfadingEdgeWidth
(dimension): the width of both fading edges*fadingEdgeWidth
(dimension): the width of a specific fading edgefadingEdgeVisibilityThreshold
(dimension): the visibility threshold for the fading edgesfadingEdgeVisibilityInteropolator
(path toTimeInterpolator
implementation): the visibility interpolator for fading edgeshorizontalLayout
(segmented
orfullWidth
): the chart’sHorizontalLayout
scalableStartContentPadding
(dimension): equivalent toHorizontalLayout.FullWidth#scalableStartPaddingDp
scalableEndContentPadding
(dimension): equivalent toHorizontalLayout.FullWidth#scalableEndPaddingDp
unscalableStartContentPadding
(dimension): equivalent toHorizontalLayout.FullWidth#unscalableStartPaddingDp
unscalableEndContentPadding
(dimension): equivalent toHorizontalLayout.FullWidth#unscalableEndPaddingDp
ChartView
ChartView
has all the attributes of BaseChartView
, plus the following:
chart
(column
,stackedColumn
, orline
): the chart type
ComposedChartView
ComposedChartView
has all the attributes of BaseChartView
, plus the following:
charts
(pipe-separated combination ofcolumn
,stackedColumn
, andline
): the chart types
Attribute sets
Axis
axisLineStyle
(LineComponentStyle
): the style of the axis lineaxisGuidelineStyle
(LineComponentStyle
): the style of axis guidelinesaxisTickStyle
(LineComponentStyle
): the style of axis ticksaxisLabelStyle
(TextComponentStyle
): the style of axis labelsaxisTickLength
(dimension): the length of axis ticksaxisLabelBackground
(color orShape
): the background for axis labelsverticalAxisHorizontalLabelPosition
(outside
orinside
): the horizontal position of the labels on this axis if it is verticalverticalAxisVerticalLabelPosition
(top
,center
, orbottom
): the vertical position of the labels on this axis is if it verticallabelRotationDegrees
(floating-point number): the rotation of axis labels in degreestitle
(string or reference): the axis titleshowTitle
(boolean or reference): whether to display the axis titletitleStyle
(TextComponentStyle
): the style of the axis titlehorizontalAxisLabelSpacing
(integer): the label spacing for this axis if it is horizontalhorizontalAxisLabelOffset
(integer): the label offset for this axis if it is horizontalshowAxisLine
(boolean): whether to display the axis lineshowGuideline
(boolean): whether to display guidelinesshowTick
(boolean): whether to display ticksshiftExtremeHorizontalAxisTicks
(boolean): equivalent to theshiftExtremeTicks
parameter ofAxisItemPlacer.Horizontal.default
addExtremeHorizontalAxisLabelPadding
(boolean): equivalent to theaddExtremeLabel
parameter ofAxisItemPlacer.Horizontal.default
shiftTopVerticalAxisLines
(boolean): equivalent to theshiftTopLines
parameter ofAxisItemPlacer.Vertical.default
maxVerticalAxisItemCount
(integer): equivalent to themaxItemCount
parameter ofAxisItemPlacer.Vertical.default
ComponentStyle
color
(color): the background colorshapeStyle
(Shape
): the shape stylestrokeColor
(color): the stroke colorstrokeWidth
(dimension): the stroke widthoverlayingComponentStyle
(ComponentStyle
): a component with which to overlay this componentoverlayingComponentPadding
(dimension): the padding between this component and the component with which it is overlaid
ColumnChartStyle
column1Style
(ComponentStyle
): the style for columns whose index in a column collection is 3k (k ∈ N)column2Style
(ComponentStyle
): the style for columns whose index in a column collection is 1 + 3k (k ∈ N)column3Style
(ComponentStyle
): the style for columns whose index in a column collection is 2 + 3k (k ∈ N)columnOuterSpacing
(dimension): the distance between neighboring column collectionscolumnInnerSpacing
(dimension): the distance between neighboring grouped columnsshowDataLabels
(boolean): whether to show data labelsdataLabelStyle
(TextComponentStyle
): the style of data labelsdataLabelVerticalPosition
(top
,center
, orbottom
): the vertical position of each data label relative to the top edge of its respective columndataLabelRotationDegrees
(floating-point number): the rotation of data labels in degrees
TextComponentStyle
labelColor
(color): the text colorbackgroundStyle
(ComponentStyle
): the background for the labelandroid:padding
(dimension): the padding for each edge of the labelandroid:padding*
(dimension): the padding for a specific edge or edge pair of the labelandroid:fontFamily
(sans-serif
,sans-serif-*
, or@font
reference): the font familyandroid:textFontWeight
(integer between 100 and 900): the font weightandroid:fontStyle
(normal
oritalic
): the font styleandroid:textSize
(dimension): the text sizeandroid:ellipsize
(start
,end
,middle
,none
, ormarquee
): the text truncation behaviortypeface
(normal
,sans
,serif
, ormonospace
): the typefacemargin
(dimension): the size of all four marginsmargin*
(dimension): the size of a specific margin or margin pairtextAlignment
(normal
,center
, oropposite
): the text alignment
LineChartStyle
line1Spec
(LineSpec
): the style for lines whose index in the list of lines in a line chart is 3k (k ∈ N)line2Spec
(LineSpec
): the style for lines whose index in the list of lines in a line chart is 1 + 3k (k ∈ N)line3Spec
(LineSpec
): the style for lines whose index in the list of lines in a line chart is 2 + 3k (k ∈ N)spacing
(dimension): the point spacing
LineComponentStyle
color
(color): the background colorthickness
(dimension): the line thicknessshapeStyle
(Shape
): the shape of the linestrokeColor
(color): the stroke colorstrokeWidth
(dimension): the stroke width
LineSpec
color
(color): the line colorgradientTopColor
(color): the top color of the vertical background gradientgradientBottomColor
(color): the bottom color of the vertical background gradientpointSize
(dimension): the point sizelineThickness
(dimension): the thickness of the linepointStyle
(ComponentStyle
): the style of pointscubicStrength
(fraction): the strength of the cubic bezier curve between each key point on the lineshowDataLabels
(boolean): whether to show data labelsdataLabelStyle
(TextComponentStyle
): the style of data labelsdataLabelVerticalPosition
(top
,center
, orbottom
): the vertical position of each data label relative to its respective point on the linedataLabelRotationDegrees
(floating-point number): the rotation of data labels in degrees
Shape
cornerSize
(dimension or fraction): the corner sizecornerTreatment
(rounded
orcut
): the corner styletopStartCornerSize
(dimension or fraction): the size of the top-start cornertopEndCornerSize
(dimension or fraction): the size of the top-end cornerbottomStartCornerSize
(dimension or fraction): the size of the bottom-start cornerbottomEndCornerSize
(dimension or faction): the size of the bottom-end cornerdashLength
(dimension): the dash length (0 means no dashes)dashGapLength
(dimension): the dash gap length (0 means no dashes)