Simple graphic representation of data changing during the time
- Copy
chartLib
as module to your project - In
settings.gradle
file add library as module':chartLib'
, so the file should look like
include ':chartLib', ':YOUR_APP_NAME'
- In module level
build.gradle
file add next line to blockdependencies
dependencies{
implementation project(':chartLib')
}
- Declare TimeLineChart view in your layout as shown below
<com.contest.chart.TimeLineChart
android:id="@+id/chart"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
- Find chart view and set prepared data
val chartData : LineChartData = prepareData()
val chart: TimeLineChart = findViewById(R.id.chart)
chart.setTitle("YOUR CHART TITLE")
chart.setData(chartData)
- Chart supports Light and Dark themes, to switch between them just call method
switchTheme()
on class instance
chart.switchTheme()
- In order to represent your data, chart requires you to provide data as instance of class
LineChartData
class LineChartData(val id: Int) {
val brokenLines = ArrayList<BrokenLine>()
lateinit var timeLine: LongArray
}
Field timeLine
is array of long
that represented time line during wich your data changes.
Since chart can represent a few chart lines simultaneously in one view with the same time frame, you need to provide your data as instance of class BrokenLine
and add it to brokenLines
list.
Class BrokenLine
declaration
class BrokenLine(val points: FloatArray, val name: String, val color: String)
where:
points
- array of values of your data
name
- name of data
color
- color in HEX format
IMPORTANT: size of points
and timeLine
arrays should be always equal
- Min API level 21