Skip to content

valerybodak/graphty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graphty

Android Library to display graphs

graphty_bg

Installation

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

Add the following dependency in your app build.gradle:

implementation 'com.github.valerybodak:Graphty:1.0.7'

Usage

1. WeekLineGraph

1.1 Put WeekLineGraph to your xml layout

<com.vbodak.graphtylib.graph.week.WeekLineGraph
    android:id="@+id/weekLineGraph"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

1.2 Setup WeekLineGraph and display it

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)
)

1.3 Params

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.

2. BarGraph

2.1 Put BarGraph to your xml layout

<com.vbodak.graphtylib.graph.bar.BarGraph
    android:id="@+id/barGraph"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

2.2 Setup BarGraph and display it

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))
    )
)

2.3 Params

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

Developed By

License

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.