当前位置:网站首页>Compose Canvas line chart
Compose Canvas line chart
2022-07-26 07:17:00 【Ango can't move】
package com.anguomob.compose.ui.components
import android.util.Log
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.ConstraintSet
import androidx.constraintlayout.compose.Dimension
import coil.compose.AsyncImage
import com.anguomob.compose.model.ArticleEntity
import com.anguomob.compose.model.VideoEntity
private const val TAG = "ChartView"
@Composable
fun ChartView(modifier: Modifier = Modifier, points: List<Float>) {
// The height of each line
val heightForRow = 24
// Total number of lines
val countForRow = 5
// Small circle radius
val circleRadius = 2.5
// Canvas width
val canvasWidth = LocalConfiguration.current.screenWidthDp - 8 * 2
// Canvas height
val canvasHeight = heightForRow * countForRow + circleRadius * 2
// no 8 dp representative 1 integral Every line 3 integral
val perY = 8 //24 * 5 /15
// Bisector width
val averageOfWidth = canvasWidth / 7
Canvas(modifier = modifier.size(width = canvasWidth.dp, canvasHeight.dp), onDraw = {
// Background horizontal line
for (index in 0..countForRow) {
val startY = (index * heightForRow.toFloat() + circleRadius).dp.toPx()
val endX = size.width
val endY = startY
drawLine(Color(0xFFEEEEEE),
start = Offset(x = 0f, y = startY),
end = Offset(x = endX, y = endY),
strokeWidth = 2.5f)
}
// Draw a small circle 、 Broken line
for (index in 0 until points.count()) {
Log.e(TAG, "index:${index} ");
val centerX = (averageOfWidth * index + averageOfWidth / 2).dp.toPx()
val centerY =
(heightForRow * countForRow - points[index] * perY + circleRadius).dp.toPx()
val circleCenter = Offset(centerX, centerY)
// spot
drawCircle(Color(0xff149ee7), radius = circleRadius.dp.toPx(),
center = circleCenter,
style = Stroke(width = 5f)
)
// Line
if (index < points.count() - 1) {
val nextPointOffsetX = (averageOfWidth * (index + 1) + averageOfWidth / 2).dp.toPx()
val nextPointOffsetY =
(heightForRow * countForRow - points[(index + 1)] * perY + circleRadius).dp.toPx()
val nextPoint = Offset(nextPointOffsetX, nextPointOffsetY)
drawLine(Color(0xFF149EE7), start = circleCenter, end = nextPoint, strokeWidth = 5f)
}
}
})
}
The data is
var pointsOfWeek by mutableStateOf(listOf(3f, 2f, 6f, 9.3f, 10f, 15f, 8f))
private setThe effect is

The next few weeks are because there is no drawText
therefore
Row() {
taskViewModel.weeks.forEach {
Text(text = it,
color = Color(0xff999999),
fontSize = 12.sp,
modifier = Modifier.weight(1f),
textAlign = TextAlign.Center
)
}
}
val weeks = listOf("02.05", "02.06", "02.07", "02.08", "02.09", "02.10", " Today, ")
边栏推荐
- Orthogonality of 20220724 trigonometric function system
- Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV
- From scratch, we will completely develop an online chess game [Gobang] Based on websocket, and only use dozens of lines of code to complete all the logic.
- NFT数字藏品系统开发:数字藏品赋予品牌新活力
- Drools (3): drools basic syntax (1)
- Opencv learning warp Perspective
- The method of raspberry pie connecting tmall elf speaker to play music through Bluetooth
- It's another summer of open source. 12000 project bonuses are waiting for you!
- [yiku] wonderful! This library organization NPM script is simply explosive!
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 1 supplementary question record (acdgij)
猜你喜欢

NFT数字藏品开发:数字藏品与NFT的六大区别

Differences in the use of function call pointer parameters *p, * & P

HCIP --- MPLS技术

File server fastdfs

Become an Apache contributor, so easy!

文件服务器FastDFS

MySQL execution plan
![Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV](/img/10/40d02da10a6f6779635dc820c074c6.png)
Rgb-t tracking - [dataset benchmark] gtot / rgbt210 / rgbt234 / vot-2019-2020 / laser / VTUAV

4、数据的完整性

QT: list box, table, tree control
随机推荐
Basic operations and common functions of MySQL table creation
Idea -- use @slf4j to print logs
It's another summer of open source. 12000 project bonuses are waiting for you!
数据平台调度升级改造 | 从Azkaban 平滑过度到 Apache DolphinScheduler 的操作实践
MySQL安装教程-手把手教你安装
HCIP --- MPLS技术
Flame diagram analysis Flink backpressure
Contents mismatch at: 08000000H (Flash=FFH Required=00H) ! Too many errors to display !
shape 和 size() 区别
Image annotation software reference
Deep learning learning notes -- solve the problem of slow download of CONDA and pip
Drools (3): drools basic syntax (1)
3.0.0 alpha 重磅发布!九大新功能、全新 UI 解锁调度系统新能力
Opencv learning drawing shapes and text
Acwing- daily question
Unity3d asynchronous loading of scenes and progress bar loading
从XSS Playload 学习浏览器解码
Airiot IOT platform enables the container industry to build a welding station information monitoring system
Heap parsing and heap sorting
单身杯web wp