A basic chart written by kotlin. Support animation loading, touch event monitoring and JSON data.

Overview

一款轻量级android图表组件SimpleChart-Kotlin

效果演示

基础效果演示

引入方式

gradle导入

  1. 在更目录中的build.gradle添加 JitPack仓库

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

    以上是官方提供的添加仓库方法,实测在较新的gradle版本中此方式无法成功生效,而是需要在settings.gradle中添加:

    dependencyResolutionManagement {
    	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    	repositories {
        	...
        	maven { url 'https://jitpack.io' }
     }
    }
  2. 添加依赖

    dependencies {
        implementation 'com.github.EnthuDai:SimpleChart-Kotlin:1.0.7'
    }	

PS: 发布一个kotlin的android library到jitpack的过程极为艰难,尤其是在使用较新版本的gradle时,大家如果遇到问题,可以参考一下这篇文章

kotlin android library 发布至jitpack问题及解决方式记载

源码导入

  1. 下载该项目源码

    git clone https://github.com/EnthuDai/SimpleChart-Kotlin.git
  2. 在需要使用该库的项目中通过文件导入此模块 导入模块步骤1 导入模块步骤二,选择上一步中下载项目的chart文件夹

  3. 在app的build.gradle的依赖中添加此库

    dependencies {
    
    	...
    
     implementation project(':chart')
    }

使用方式

布局文件

">
<com.poemdistance.chart.BarChart
        android:id="@+id/barChart"
        android:layout_width="0dp"
        android:layout_height="300dp"
        app:title="柱状图"
        app:xAxis="staDate"
        app:yAxis="profit"
        app:yAxisDesc="入账收益"/>

设置数据

数据设置的方式非常简单,支持直接传入JSON数组字符串,或传入List< Any>形式的对象集合。所有类型图表均支持这两种方式的数据传入。JSON数组字符串的导入代码如下:

val jsonData = """
        [{"staDate":"01-09","profit":235,"activeOrderCount":36},
        {"staDate":"01-08","profit":244,"activeOrderCount":33},
        {"staDate":"01-07","profit":159,"activeOrderCount":29},
        {"staDate":"01-06","profit":452,"activeOrderCount":48},
        {"staDate":"01-05","profit":116,"activeOrderCount":19},
        {"staDate":"01-04","profit":131,"activeOrderCount":22},
        {"staDate":"01-03","profit":345,"activeOrderCount":32},
        {"staDate":"01-02","profit":277,"activeOrderCount":35},
        {"staDate":"01-01","profit":206,"activeOrderCount":28}]
    """.trimIndent()
barChart.updateData(jsonData) // barChart为该图表的实例

事件监听

监听用户当前触摸的数据项

// 监听触摸事件,将获得Json字符串形式的当前触控数据,当触控点从图表移开时返回null
barChart.listener =  {
	it?.let{
		Log.d(LOG_TAG, it)
	}
}

配置项

所有图表均具备的配置项

属性名 类型 默认值 含义
title String 图表标题
animation Boolean True 是否开启加载动画
animationDuration Int 500 加载动画时长
showLegend Boolean 自动(单维度数据时不显示) 是否显示图例

柱状图

属性名 类型 默认值 含义 是否必填
xAxis String x轴数据的参数名
yAxis String y轴数据的参数名
yAxisDesc String yAxis值 描述y轴数据项的参数名

折线图

属性名 类型 默认值 含义 是否必填
xAxis String x轴数据的参数名
yAxis String y轴数据的参数名,支持多个,用“,”分隔
yAxisDesc String yAxis值 描述y轴数据项的参数名,支持多个,用“,”分隔

饼图

属性名 类型 默认值 含义 是否必填
name String 数据项的展示参数名
value String 数据项的值参数名
You might also like...
Straiberry Charts - An awesome Chart library for android
Straiberry Charts - An awesome Chart library for android

Straiberry Charts An awesome Chart library for android Straiberry · Report Bug · Request Feature Getting Started Adding dependecies Add it in your roo

An Elementary Chart library for Jetpack Compose
An Elementary Chart library for Jetpack Compose

Charty : Elementary Chart library for Compose Chart Library built using Jetpack Compose and is highly customizable. Updates coming soon! Made with ❤️

An easy-to-use Android charts library with animation.
An easy-to-use Android charts library with animation.

AndroidCharts A simple Android charts library. Known Uses in Pomotodo Including in Your Project Eclipse Import /AndroidCharts folder. Move /java folde

Data2Viz port/wrapper for data visualization with Jetpack Compose
Data2Viz port/wrapper for data visualization with Jetpack Compose

Collage Data2Viz port/wrapper for Jetpack Compose. It is a visualization library, same as Data2Viz and d3. This is obviously not an official Data2Viz

A vector-drawing program in Kotlin and Java FX
A vector-drawing program in Kotlin and Java FX

Artist This is a vector-drawing program in Kotlin/Java FX. Your program will allow a user to select shapes to draw, set their properties, and draw the

Android Graph Library for creating zoomable and scrollable line and bar graphs.
Android Graph Library for creating zoomable and scrollable line and bar graphs.

Chart and Graph Library for Android Project maintainer wanted! For time reasons I can not continue to maintain GraphView. Contact me if you are intere

Android Graph Library for creating zoomable and scrollable line and bar graphs.
Android Graph Library for creating zoomable and scrollable line and bar graphs.

Chart and Graph Library for Android Project maintainer wanted! For time reasons I can not continue to maintain GraphView. Contact me if you are intere

Android Library to rapidly develop attractive and insightful charts in android applications.
Android Library to rapidly develop attractive and insightful charts in android applications.

williamchart Williamchart is an Android Library to rapidly implement attractive and insightful charts in android applications. Note: WilliamChart v3 h

TChart - Simple and fast charts.
TChart - Simple and fast charts.

TChart - Simple and fast charts.

Owner
null
Open-source native Android graph/chart framework includes line chart,stick chart,candlestick chart,pie chart,spider-web chart etc.

Welcome to Android-Charts Welcome to Android-Charts project page on github.com. We just moved from Google Code. Android-Charts is an open-source andro

limc.cn 813 Dec 20, 2022
AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.

AnyChart for Android AnyChart Android Charts is an amazing data visualization library for easily creating interactive charts in Android apps. It runs

AnyChart 2k Jan 4, 2023
Jetpack-linear-chart - A simple way to draw linear chart using Jetpack Compose

jetpack-linear-chart A simple way to draw linear chart using Jetpack Compose We

Bruno Gabriel dos Santos 8 Jan 4, 2023
Charts/graphs library for Android compatible with API 8+, several chart types with support for scaling, scrolling and animations

HelloCharts for Android Charting library for Android compatible with API 8+(Android 2.2). Works best when hardware acceleration is available, so API 1

Leszek Wach 7.4k Jan 6, 2023
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚡ A powerful & easy to use chart library for Android ⚡ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

Philipp Jahoda 36k Dec 31, 2022
An Android chart and graph library

EazeGraph EazeGraph is an Android library for creating beautiful and fancy charts. Its main goal was to create a lighweight library which is easy to u

Paul Cech 1.6k Dec 23, 2022
A powerful 🚀 Android range bar chart library as well as scaling, panning and animations.

RangeBarChart ⚡ Range bar chart library for Android using MPAndroidChart ⚡ There were no charts in MPAndroidChart to show ranges. We were forced to sh

Ted Park 8 Nov 24, 2022
Arc Chart View (Draw Creative Statistic Arc Charts)

ArcChartViewDemo You can use this library to draw Arc charts and show your statistics or anything you want or maybe get some ratings from user. you ca

Iman khoshabi 106 Nov 22, 2022
Simple Line, Circle, Bar chart for Android

SimpleChart Simple Line, Circle, Bar chart for Android LineChart <com.aghajari.simplechart.LineChart android:id="@+id/line_chart" android:layo

AmirHosseinAghajari 5 Jul 28, 2022
ChartPOC - Chart POC-Android

ChartPOC Chart POC-Android Time Frame Bar Chart Component To use the component j

null 1 Jan 13, 2022