앞서 jaikeerthick/Composable-Graphs 를 사용해보았는데,
아쉬운 점이 많았다.
그래서 vico를 사용해보았다.
https://github.com/patrykandpatrick/vico
아래 코드도 추가
dependencies {
// Provides the utilities needed to use Vico in the view system.
implementation "com.patrykandpatrick.vico:views:1.6.3"
// Provides the utilities needed to use Vico in Jetpack Compose.
implementation "com.patrykandpatrick.vico:compose:1.6.3"
// An optional addition for `vico.compose` that creates a `ChartStyle` based on an M2 Material Theme.
implementation "com.patrykandpatrick.vico:compose-m2:1.6.3"
// An optional addition for `vico.compose` that creates a `ChartStyle` based on an M3 Material Theme.
implementation "com.patrykandpatrick.vico:compose-m3:1.6.3"
...
}
내경우엔 아래와같이 괄호가 있어야 에러가 나지 않았다.
// Provides the utilities needed to use Vico in the view system.
implementation("com.patrykandpatrick.vico:views:1.6.3")
// Provides the utilities needed to use Vico in Jetpack Compose.
implementation("com.patrykandpatrick.vico:compose:1.6.3")
// An optional addition for `vico.compose` that creates a `ChartStyle` based on an M2 Material Theme.
implementation("com.patrykandpatrick.vico:compose-m2:1.6.3")
// An optional addition for `vico.compose` that creates a `ChartStyle` based on an M3 Material Theme.
implementation("com.patrykandpatrick.vico:compose-m3:1.6.3")
그런데 안된다...???
Column() {
val producer = ChartEntryModelProducer(getRandomEntries())
Chart(
chart = lineChart(),
chartModelProducer = producer,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
)
}
function 밖에 getRandomEntries()를 만들어 일단 랜덤한 데이터를 가져온다.
fun getRandomEntries() = List(size = 5) {
25f * Random.nextFloat()
}.mapIndexed { x, y ->
FloatEntry(
x = x.toFloat(),
y = y,
)
}