Last active
January 30, 2023 18:11
-
-
Save giovanileitevitor/bdb82eafa9a92877d9c8510e6bb7d082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun GraphicBox(values: List<Float>, labels: List<String>) { | |
val context = LocalContext.current | |
// BarGraph Dimensions | |
val barGraphHeight by remember { mutableStateOf(200.dp) } | |
val barGraphWidth by remember { mutableStateOf(24.dp) } | |
Column( | |
modifier = Modifier | |
.padding(start = 10.dp, end = 10.dp, top = 4.dp) | |
.fillMaxWidth() | |
.fillMaxSize(), | |
verticalArrangement = Arrangement.Top | |
) { | |
/* Data */ | |
Row( | |
modifier = Modifier | |
.fillMaxWidth() | |
.height(barGraphHeight), | |
verticalAlignment = Alignment.Bottom, | |
horizontalArrangement = Arrangement.Start | |
) { | |
values.forEach() { value -> | |
Box( | |
modifier = Modifier | |
.padding(start = 4.dp, bottom = 0.dp, end = 4.dp, top = 10.dp) | |
.width(width = barGraphWidth) | |
.weight(1f) | |
.fillMaxHeight(value) | |
.background(randomColors()) | |
.clickable(role = Role.Button, onClickLabel = "Item Gráfico") { | |
Toast.makeText(context, "Valor: $value", Toast.LENGTH_SHORT).show() | |
}) | |
} | |
} | |
/* Labels*/ | |
Row( | |
modifier = Modifier | |
.fillMaxWidth().height(20.dp), | |
verticalAlignment = Alignment.Bottom, | |
horizontalArrangement = Arrangement.Start | |
) { | |
labels.forEach() { | |
Box( | |
modifier = Modifier | |
.weight(1f) | |
.width(width = 10.dp), | |
contentAlignment = Alignment.Center | |
) { | |
Text( | |
text = it, | |
color = Color.Black, | |
fontSize = 8.sp, | |
fontWeight = FontWeight.Bold | |
) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment