Android Library to display graphs
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the following dependency in your app build.gradle:
implementation 'com.github.valerybodak:Graphty:1.0.7'
<com.vbodak.graphtylib.graph.week.WeekLineGraph
android:id="@+id/weekLineGraph"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
val params = WeekLineGraphParams()
params.minValue = 0
params.maxValue = 950
params.valueScaleWidthPx = 82F
params.titleTextSize = 30F
params.weekdayStart = Calendar.SUNDAY
params.weekdayNameMap = mapOf(
Calendar.SUNDAY to "S",
Calendar.MONDAY to "M",
Calendar.TUESDAY to "T",
Calendar.WEDNESDAY to "W",
Calendar.THURSDAY to "T",
Calendar.FRIDAY to "F",
Calendar.SATURDAY to "S"
)
binding.weekGraph.setup(
params = params
)
...
binding.weekGraph.draw(
values = listOf<Int>(32, 176, 33, 568, 7, 65, 43)
)
Property | Type | Description |
---|---|---|
minValue | Int | Min value to display on the left side scale. In case is not specified the min value from values list will be applied |
maxValue | Int | Max value to display on the left side scale. In case is not specified the max value from values list will be applied |
valueScaleWidthPx | Float | The width of the left side panel of values |
valueTextSize | Float | The text size of values on the left side panel |
valueTextColor | Int | The color (@ColorRes) of values on the left side panel |
titleScaleHeightPx | Float | The height of the bottom panel with titles |
titleTextSize | Float | The text size of titles on the bottom panel |
titleTextColor | Int | The color (@ColorRes) of titles on the bottom panel |
lineWidth | Float | The width of graph's line |
lineColor | Int | The color (@ColorRes) of graph's line |
enableGuidelines | Boolean | Enable / Disable vertical guidelines |
guidelineWidth | Float | The width of guideline |
guidelineColor | Int | The color (@ColorRes) of guideline |
nodesMode | NodesMode | 1. NodesMode.NONE - to disable nodes. 2. NodesMode.ALL - to display the node for each value, 3. NodesMode.MAX - to display the node only for the max value |
nodeRadiusPx | Float | The node's radius |
nodeFillColor | Int | The color (@ColorRes) of node |
weekdayStart | Int | The first day of the week. Use the Calendar's contsants: Calendar.MONDAY, Calendar.SUNDAY etc. |
weekdayNameMap | Map<Int, String> | The mapping to display the weekday titles. The key is Calendar's contsant (Calendar.MONDAY, Calendar.TUESDAY etc.). The value is the weekday's text representation, for example, "M", "T", "W" etc. |
<com.vbodak.graphtylib.graph.bar.BarGraph
android:id="@+id/barGraph"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
val params = BarGraphParams()
params.minValue = 5
params.maxValue = 100
params.valueScaleWidthPx = 82F
params.titleTextSize = 30F
params.barColors = listOf(R.color.cyan, R.color.pink, R.color.yellow)
params.barCornerRadiusPx = 6F
binding.barGraph.setup(
params = params
)
...
binding.barGraph.draw(
bars = listOf(
Bar(title = "12/10", values = listOf(80, 10, 98)),
Bar(title = "13/10", values = listOf(65, 87, 76)),
Bar(title = "14/10", values = listOf(69, 32, 15)),
Bar(title = "15/10", values = listOf(46, 15, 23)),
Bar(title = "16/10", values = listOf(96, 87, 78)),
Bar(title = "17/10", values = listOf(78, 76, 54)),
Bar(title = "18/10", values = listOf(70, 60, 43))
)
)
Property | Type | Description |
---|---|---|
minValue | Int | Min value to display on the left side scale. In case is not specified the min value from values list will be applied |
maxValue | Int | Max value to display on the left side scale. In case is not specified the max value from values list will be applied |
valueScaleWidthPx | Float | The width of the left side panel of values |
valueTextSize | Float | The text size of values on the left side panel |
valueTextColor | Int | The color (@ColorRes) of values on the left side panel |
titleScaleHeightPx | Float | The height of the bottom panel with titles |
titleTextSize | Float | The text size of titles on the bottom panel |
titleTextColor | Int | The color (@ColorRes) of titles on the bottom panel |
barColors | List | The colors (@ColorRes) of bars |
barWidthPx | Float | The bar's width |
barCornerRadiusPx | Float | The corner's radius of bar |
- Valery Bodak - [email protected]
Copyright 2023 Valery Bodak
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.