Skip to content

Commit

Permalink
修改示例成交量图空心样式
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Dec 15, 2021
1 parent f82d8ad commit eadbd46
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -753,61 +753,40 @@ open class KChart(
hollowKChartPaint.color =
if (kEntity.getClosePrice() >= kEntity.getOpenPrice()) stockChart.getConfig().riseColor else stockChart.getConfig().downColor

if (kEntity.getClosePrice() >= kEntity.getOpenPrice()) { // 空心阳线
tmp24FloatArray[0] = left
tmp24FloatArray[1] = kEntity.getOpenPrice()
tmp24FloatArray[2] = left
tmp24FloatArray[3] = kEntity.getClosePrice()

tmp24FloatArray[4] = left
tmp24FloatArray[5] = kEntity.getOpenPrice()
tmp24FloatArray[6] = left + barWidth
tmp24FloatArray[7] = kEntity.getOpenPrice()

tmp24FloatArray[8] = left + barWidth
tmp24FloatArray[9] = kEntity.getOpenPrice()
tmp24FloatArray[10] = left + barWidth
tmp24FloatArray[11] = kEntity.getClosePrice()

tmp24FloatArray[12] = left
tmp24FloatArray[13] = kEntity.getClosePrice()
tmp24FloatArray[14] = left + barWidth
tmp24FloatArray[15] = kEntity.getClosePrice()

tmp24FloatArray[16] = left + barWidth / 2
tmp24FloatArray[17] = kEntity.getHighPrice()
tmp24FloatArray[18] = left + barWidth / 2
tmp24FloatArray[19] = max(kEntity.getOpenPrice(), kEntity.getClosePrice())

tmp24FloatArray[20] = left + barWidth / 2
tmp24FloatArray[21] = kEntity.getLowPrice()
tmp24FloatArray[22] = left + barWidth / 2
tmp24FloatArray[23] = min(kEntity.getOpenPrice(), kEntity.getClosePrice())

mapPointsValue2Real(tmp24FloatArray)
canvas.drawLines(tmp24FloatArray, hollowKChartPaint)
} else { // 实心阴线
tmp4FloatArray[0] = left + barWidth / 2
tmp4FloatArray[1] = kEntity.getHighPrice()
tmp4FloatArray[2] = left + barWidth / 2
tmp4FloatArray[3] = kEntity.getLowPrice()
mapPointsValue2Real(tmp4FloatArray)
canvas.drawLines(tmp4FloatArray, hollowKChartPaint)
tmpRectF.left = left
tmpRectF.top = kEntity.getOpenPrice()
tmpRectF.right = left + barWidth
tmpRectF.bottom = kEntity.getClosePrice()
mapRectValue2Real(tmpRectF)
canvas.drawRect(tmpRectF, hollowKChartPaint)
}
tmp4FloatArray[0] = left + barWidth / 2
tmp4FloatArray[1] = kEntity.getHighPrice()
tmp4FloatArray[2] = tmp4FloatArray[0]
tmp4FloatArray[3] = max(kEntity.getOpenPrice(), kEntity.getClosePrice())
mapPointsValue2Real(tmp4FloatArray)
canvas.drawLines(tmp4FloatArray, hollowKChartPaint)

tmp4FloatArray[0] = left + barWidth / 2
tmp4FloatArray[1] = kEntity.getLowPrice()
tmp4FloatArray[2] = tmp4FloatArray[0]
tmp4FloatArray[3] = min(kEntity.getOpenPrice(), kEntity.getClosePrice())
mapPointsValue2Real(tmp4FloatArray)
canvas.drawLines(tmp4FloatArray, hollowKChartPaint)

tmpRectF.left = left
tmpRectF.top = kEntity.getOpenPrice()
tmpRectF.right = left + barWidth
tmpRectF.bottom = kEntity.getClosePrice()
mapRectValue2Real(tmpRectF)
hollowKChartPaint.style = if (kEntity.getClosePrice() >= kEntity.getOpenPrice()) {
// 空心阳线
Paint.Style.STROKE
} else {
Paint.Style.FILL
}
canvas.drawRect(tmpRectF, hollowKChartPaint)
}
left += barWidth + spaceWidth
}
}

private fun drawCandleKChart(canvas: Canvas) {
candleKChartPaint.strokeWidth = chartConfig.candleChartLineStrokeWidth

val barWidth = 1 * (1 - chartConfig.barSpaceRatio)
val spaceWidth = 1 * chartConfig.barSpaceRatio
var left = spaceWidth / 2f
Expand All @@ -818,7 +797,7 @@ open class KChart(
candleKChartPaint.color = candleKChartPaint.color
tmp4FloatArray[0] = left + barWidth / 2
tmp4FloatArray[1] = kEntity.getHighPrice()
tmp4FloatArray[2] = left + barWidth / 2
tmp4FloatArray[2] = tmp4FloatArray[0]
tmp4FloatArray[3] = kEntity.getLowPrice()
mapPointsValue2Real(tmp4FloatArray)
canvas.drawLines(tmp4FloatArray, candleKChartPaint)
Expand All @@ -827,17 +806,9 @@ open class KChart(
tmpRectF.right = left + barWidth
tmpRectF.bottom = kEntity.getClosePrice()
mapRectValue2Real(tmpRectF)
if (tmpRectF.height() == 0f) {
canvas.drawLine(
tmpRectF.left,
tmpRectF.top,
tmpRectF.right,
tmpRectF.bottom,
candleKChartPaint
)
} else {
canvas.drawRect(tmpRectF, candleKChartPaint)
}
candleKChartPaint.style =
if (tmpRectF.height() == 0f) Paint.Style.STROKE else Paint.Style.FILL
canvas.drawRect(tmpRectF, candleKChartPaint)
}
left += barWidth + spaceWidth
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class VolumeChart(
}

private fun drawVolumeChart(canvas: Canvas, isHollow: Boolean) {
volumePaint.strokeWidth = chartConfig.hollowChartLineStrokeWidth
val barWidth = 1 * (1 - chartConfig.barSpaceRatio)
val spaceWidth = 1 * chartConfig.barSpaceRatio
var left = spaceWidth / 2f
Expand All @@ -92,7 +93,6 @@ class VolumeChart(
}
volumePaint.color =
if (isRise) stockChart.getConfig().riseColor else stockChart.getConfig().downColor
volumePaint.strokeWidth = chartConfig.hollowChartLineStrokeWidth
if (kEntity.getClosePrice() >= kEntity.getOpenPrice() && isHollow) { // 空心
volumePaint.style = Paint.Style.STROKE
} else {
Expand Down
4 changes: 2 additions & 2 deletions samples/build.gradle
Original file line number Diff line number Diff line change
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.0.13'
implementation project(':lib')
// implementation 'com.github.wangyiqian:StockChart:1.0.13'
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class Sample2Activity : AppCompatActivity() {
Util.formatVolume(volume = volume.toLong())
}
)

// 柱子空心时的线条宽度
hollowChartLineStrokeWidth = DimensionUtil.dp2px(this@Sample2Activity, 1f).toFloat()

}

}
Expand Down

0 comments on commit eadbd46

Please sign in to comment.