An awesome Chart library for android

An awesome Chart library for android

An awesome Chart library for android

Straiberry Charts

An awesome Chart library for android Straiberry · Report Bug · Request Feature

Getting Started

Adding dependecies

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

	allprojects {
  	repositories {
  		...
  		maven { url 'https://jitpack.io' }
  	}
  }
  1. Add the dependency

	dependencies {
          implementation 'com.github.STRAIBERRY-AI-INC:Straiberry-charts:1.1.0'
  }

How it’s work

There is four type of chart in this library:

  1. Horizontal Bar Chart

An awesome Chart library for android

  <com.straiberry.android.charts.view.HorizontalBarChartView
            android:id="@+id/horizontalBarChartViewBrushingDigit"
            style="@style/HorizontalChart"
            android:layout_width="310dp"
            android:layout_height="170dp"
            android:layout_marginBottom="10dp"
            android:clickable="false"
            android:focusable="false"
            app:chart_barsColorsList="@array/BrushingChartFilterColor"
            app:chart_barsRadius="17dp"
            app:chart_grid="full"
            app:chart_horizontal_y_label_type="fromZeroToSeven" or "isCharacter"
            app:chart_labelsSize="8sp"
            app:chart_spacing="13dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

Setup input data:

    /** Setup data for horizontal chart */
    private fun setupHorizontalChart() {

        val data = horizontalChartData(
            this, HorizontalChartXLabels(
                ContextCompat.getDrawable(this, R.drawable.ic_user)!!, "user",
                ContextCompat.getDrawable(this, R.drawable.ic_user)!!, "user",
                ContextCompat.getDrawable(this, R.drawable.ic_age)!!, "age",
                ContextCompat.getDrawable(this, R.drawable.ic_gender)!!, "gender",
                ContextCompat.getDrawable(this, R.drawable.ic_location)!!, "location",
                ContextCompat.getDrawable(this, R.drawable.ic_master)!!, "master",
            ), listOf(6F, 7F, 2F, 7F, 7F, 5F)
        )
        binding.horizontalBarChartViewBrushingDigit.animate(data)
    }
  1. Bar Chart

An awesome Chart library for android

 <com.straiberry.android.charts.view.BarChartView
            android:id="@+id/barChartViewBrushing"
            android:layout_width="300dp"
            android:layout_height="170dp"
            android:layout_marginBottom="10dp"
            android:clickable="false"
            android:focusable="false"
            app:chart_barsColorsList="@array/BrushingChartColor"
            app:chart_barsRadius="17dp"
            android:layout_marginTop="50dp"
            app:chart_grid="horizontal"
            app:chart_gridColorY="@color/gray400WithOpacity14"
            app:chart_labelsSize="8dp"
            app:chart_labelsXColor="@color/linkWithoutButton"
            app:chart_labelsYColor="@color/linkWithoutButton"
            app:chart_spacing="20dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/horizontalBarChartViewBrushingCharacter" />

Setup input data:

private fun setupBarChart() {
        val currentDate = Date()
        val calendar = Calendar.getInstance()
        calendar.time = currentDate
        val data: ArrayList<HashMap<String, Int?>> = arrayListOf()
        
        repeat(7){
            data.add(hashMapOf(Pair(calendar.time.convertCurrentDateToChartDate(LINE_CHART_DATE_FORMAT),it+1)))
            calendar.add(Calendar.DATE, -1)
        }
        
        binding.barChartViewBrushing.animate(data.toChartData())
    }
  1. Bar percent chart

An awesome Chart library for android

<com.straiberry.android.charts.view.BarPercentChartView
            android:id="@+id/barPercentChartWhitening"
            style="@style/WhiteningChart"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="40dp"
            android:clickable="false"
            android:focusable="false"
            android:layoutDirection="ltr"
            app:chart_axis="x"
            app:chart_labelsSize="10sp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/linearChartViewOralHygiene" />

Setup input data:

private fun setupBarPercentChart() {
        // Prepare the tooltip to show on chart
        val pointTooltip = PointTooltip()
        pointTooltip.onCreateTooltip(binding.content)
        binding.barPercentChartWhitening.apply {
            tooltip = pointTooltip
            currentAverage = 20
            average = 50
            previousAverage = 30
            createBarPercent()
            disableTouchAndClick()
        }
    }
  1. Line chart

An awesome Chart library for android

<com.straiberry.android.charts.view.LineChartView
            android:id="@+id/linearChartViewOralHygiene"
            style="@style/OralHygieneChart"
            android:layout_width="325dp"
            android:layout_height="230dp"
            android:layout_marginBottom="8dp"
            android:layoutDirection="ltr"
            android:layout_marginTop="40dp"
            app:chart_grid="vertical"
            app:chart_gridEffect="dashed"
            app:chart_gridStrokeWidth="1dp"
            app:chart_labelsSize="8sp"
            app:chart_labelsXColor="@color/linkWithoutButton"
            app:chart_labelsYColor="@color/linkWithoutButton"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/barChartViewBrushing" />

Setup input data: You can refer to sample for setting up the Line chart

Copyright 2022 Straiberry

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.

GitHub

View Github