Need some help for implementing API data in charts #371
-
for example : I extracted multiple "Score" 24.0 values into a list and I want to display it in the chart like I am doing in "val chartEntryModelProducer1 = ChartEntryModelProducer(entriesOf(4f, 12f, 8f, 16f)) " fun Function(data:ArrayList){
// shape = Shapes.roundedCornerShape(columnCornerRadius),
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello! First of all, no need to apologize. It’s a good question, and I’ll be happy to help. Start by creating a val chartEntryModelProducer = ChartEntryModelProducer() Wherever the list of scores is returned, you can add a call to chartEntryModelProducer.setEntries(scores.mapIndexed { index, score -> entryOf(index, score) }) After this is executed, the chart will be updated. Let me know if that helps. |
Beta Was this translation helpful? Give feedback.
-
Yes, thank you this works!! |
Beta Was this translation helpful? Give feedback.
Hello! First of all, no need to apologize. It’s a good question, and I’ll be happy to help. Start by creating a
ChartEntryModelProducer
and linking it to your chart. I presume you have aViewModel
, and you have access to the score list there, so you can put theChartEntryModelProducer
in theViewModel
. Please avoid instantiatingChartEntryModelProducer
in composable functions.Wherever the list of scores is returned, you can add a call to
ChartEntryModelProducer#setEntries
. You’ll have to map the scores toChartEntry
instances. Let’s say the list is calledscores
. You can use something like this: