ehsannarmani / ComposeCharts

Animated & Flexible Practical Charts For Jetpack Compose
https://ehsannarmani.github.io/ComposeCharts/
Apache License 2.0
388 stars 25 forks source link

onPieClick not working for PieChart #44

Closed ruchinraja closed 3 weeks ago

ruchinraja commented 3 weeks ago

In the given PieChart example from the documentation, the onPieClick function is not working correctly. To fix this issue, you should use rememberMutableStateOf instead of remember for the list of Pie items. This allows the data to be mutable, so it can be updated when a pie slice is clicked.

Replace

val pieData = remember {
    listOf(
        Pie(label = "Android", data = 20.0, color = Color.Red, selectedColor = Color.Green),
        Pie(label = "Windows", data = 45.0, color = Color.Cyan, selectedColor = Color.Blue),
        Pie(label = "Linux", data = 35.0, color = Color.Gray, selectedColor = Color.Yellow)
    )
}

With

val pieData = remember {
    mutableStateOf(
        listOf(
            Pie(label = "Android", data = 20.0, color = Color.Red, selectedColor = Color.Green),
            Pie(label = "Windows", data = 45.0, color = Color.Cyan, selectedColor = Color.Blue),
            Pie(label = "Linux", data = 35.0, color = Color.Gray, selectedColor = Color.Yellow)
        )
    )
}
ehsannarmani commented 3 weeks ago

Hi @ruchinraja . The given exmaple in documentation is just code to show how onPieClick works and what it can be used for. As you see , the data is not even in variable. But thank you for reporting that, i will fix that to avoid confusion.