Skip to content

Commit

Permalink
KChart 增加配置 支持指定y轴范围
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Apr 22, 2022
1 parent 02a6348 commit a758cec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ Data.loadDayData(this, 0) { kEntities: List<IKEntity> ->
|showAvgLine|是否显示分时均线。若需要显示,K线数据需带有分时均线价格。|
|avgLineColor|分时均线颜色|
|avgLineStrokeWidth|分时均线宽度|
|yValueMin|y轴范围最小值,在增加或修改K线数据之前指定才有效|
|yValueMax|y轴范围最大值,在增加或修改K线数据之前指定才有效|

##### 时间条图配置`TimeBarConfig`
|字段|描述|
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ plugins {
group='com.github.wangyiqian'

android {
compileSdkVersion 29
compileSdkVersion 32
buildToolsVersion "29.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 32
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ open class KChart(
calculateIndexList()
}

if (chartConfig.yValueMin != null && chartConfig.yValueMax != null) {
result[0] = chartConfig.yValueMin!!
result[1] = chartConfig.yValueMax!!
return
}

var yMin = 0f
var yMax = 0f

Expand Down Expand Up @@ -170,6 +176,8 @@ open class KChart(
result[0] = yMin - delta
result[1] = yMax + delta
}
chartConfig.yValueMin?.apply { result[0] = this }
chartConfig.yValueMax?.apply { result[1] = this }
}

override fun preDrawBackground(canvas: Canvas) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ open class KChartConfig(
// 分时均线颜色
var avgLineColor: Int = DEFAULT_AVG_LINE_COLOR,
// 分时均线宽度
var avgLineStrokeWidth: Float = DEFAULT_AVG_LINE_WIDTH
var avgLineStrokeWidth: Float = DEFAULT_AVG_LINE_WIDTH,
// y轴范围最小值,在增加或修改K线数据之前指定才有效
var yValueMin: Float? = null,
// y轴范围最大值,在增加或修改K线数据之前指定才有效
var yValueMax: Float? = null
) : BaseChildChartConfig(
height,
marginTop,
Expand Down
8 changes: 4 additions & 4 deletions samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ plugins {
}

android {
compileSdkVersion 29
compileSdkVersion 32
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.github.wangyiqian.stockchart.sample"
minSdkVersion 24
targetSdkVersion 29
targetSdkVersion 32
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -70,6 +70,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android:flexbox:2.0.1'

// implementation project(':lib')
implementation 'com.github.wangyiqian:StockChart:1.1.0'
implementation project(':lib')
// implementation 'com.github.wangyiqian:StockChart:1.1.0'
}

0 comments on commit a758cec

Please sign in to comment.