ehsannarmani / ComposeCharts

Animated & Flexible Practical Charts For Jetpack Compose
Apache License 2.0
118 stars 7 forks source link

IllegalStateException #8

Closed Skogstomten closed 1 week ago

Skogstomten commented 1 week ago

Copied one of the examples into my application:

ColumnChart(
      data =
          listOf(
              Bars(
                  label = "1",
                  values = listOf(Bars.Data(value = -40.0, color = SolidColor(COLOR_PRIMARY))),
              ),
              Bars(
                  label = "2",
                  values = listOf(Bars.Data(value = 50.0, color = SolidColor(COLOR_PRIMARY))),
              ),
          ),
      maxValue = 75.0,
      minValue = -75.0,
  )

This is nested within a LazyColumn, although I have verified I get the same error if I change to a Column with vertical scroll.

I get an error as such:

java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
ehsannarmani commented 1 week ago

Hi @Skogstomten , by default, the chart is set to fillMaxSize, so if you using in scrollable parent, max size means infinite size, then you should give size for that chart to work correctly, so in the end, if you pass modifier to that your column chart and a spesific size, the problem will solve