- Welcome
- Getting started
- Foundations
-
Components
- Accordion
- Alert
- Alignment
- Aria Live
- Autosuggest
- Badge
- Banner Alert
- Bar Chart
- Blockquote
- Bottom Navigation
- Bottom Sheet
- Breadcrumb
- Breakpoint
- Button
- Calendar
- Card
- Card Button
- Carousel
- Checkbox
- Chip
- Code
- Content Cards
- Data Table
- Datepicker
- Description List
- Dialog
- Divider
- Drawer
- Field Set
- Flare
- Flat List
- Flight Leg
- Floating Action Button
- Floating Notification
- Form Label
- Form Validation
- Graphic Promotion
- Horizontal Navigation
- Icon
- Image
- Infinite Scroll
- Link
- List
- Map
- Mobile Scroll Container
- Modal
- Navigation Bar
- Nudger
- Overlay
- Page Indicator
- Pagination
- Panel
- Phone Input
- Picker
- Popover
- Price
- Progress Bar
- Radio Button
- Rating
- Scrollable Calendar
- Section List
- Select
- Skeleton
- Skip Link
- Slider
- Snackbar
- Spinner
- Split Input
- Star Rating
- Switch
- Table
- Text
- Text Input
- Theming
- Ticket
- Toast
- Tooltip
- Touchable Native Feedback
- Touchable Overlay
- Content
- Accessibility
Bar Chart
Bar charts are useful for displaying comparisons between categories of data. At Skyscanner, bar charts are commonly used for displaying fare prices within a given time period e.g. a year, month or week.
Bar Chart
Default
Day | Night |
---|---|
![]() |
![]() |
Installation
Backpack Android is available through Maven Central. Check the main Readme for a complete installation guide.
Usage
The Bar Chart component can be used in both XML and Kotlin/Java, however, feeding the component with data can only be done programmatically.
Example of a Bar Chart in XML
<net.skyscanner.backpack.barchart.BpkBarChart
android:id="@+id/bar_chart"
android:layout_width="match_parent"
android:layout_height="240dp" />
Example of a Bar Chart in Kotlin
import net.skyscanner.backpack.barchart.BpkBarChart
BpkBarChart(context).apply {
model = //.. initialisation
}
To render data you need to set a view model to BarChart in code. Detailed documentation on each property of the model is available here.
Here's some basic example in Kotlin:
fun createGroup() = BpkBarChart.Group(
title = "Group Title",
items = mutableListOf<BpkBarChart.Column>().apply {
for (i in 0 until 10) {
add(BpkBarChart.Column(
title = "Bar Title",
subtitle = "Bar Subtitle",
badge = "Bar Badge",
value = 0.5f,
inactive = false
))
}
}
)
barChart.model = BpkBarChart.Model(
groups = listOf(
createGroup(),
createGroup()
),
legend = BpkBarChart.Legend(
"£",
"No Price"
)
)
Another example can be found in BarChartStory in the sample project.
Theme Props
All colours support ColorStateList.
- barChartColumnTitleColor - state_selected will be used when the bar is selected.
- barChartColumnSubtitleColor - state_selected will be used when the bar is selected.
- barChartGroupTitleColor
- barChartBarBackgroundColor - state_activated this can be used to split the colours of active/inactive sets. state_selected will be used when the bar is selected.
- barChartBarForegroundColor - state_activated this can be used to split the colours of active/inactive sets. state_selected will be used when the bar is selected.
- barChartLineColor
- barChartPopupBackgroundColor
- barChartPopupTextColor
Styles can be changed globally through bpkBarChartStyle. Check theming for more information.
Made with ❤️ by Skyscanner © 2023
© 2023 Skyscanner Backpack. Page last updated on Oct 31, 2022, 13:44