赞
踩
在更目录中的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' }
}
}
添加依赖
dependencies {
implementation 'com.github.EnthuDai:SimpleChart-Kotlin:1.0.7'
}
PS: 发布一个kotlin的android library到jitpack的过程极为艰难,尤其是在使用较新版本的gradle时,大家如果遇到问题,可以参考一下这篇文章
下载该项目源码
git clone https://github.com/EnthuDai/SimpleChart-Kotlin.git
在需要使用该库的项目中通过文件导入此模块
在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 | 数据项的值参数名 | 是 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。