Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException with CurveLineChart #57

Open
Ola-jed opened this issue Nov 3, 2022 · 3 comments
Open

IllegalArgumentException with CurveLineChart #57

Ola-jed opened this issue Nov 3, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@Ola-jed
Copy link

Ola-jed commented Nov 3, 2022

I am using CurveLineChart to display some data.

Here is the code that displays the chart

CurveLineChart(
    modifier = Modifier
        .fillMaxWidth()
        .padding(vertical = 10.dp),
    lineData = lineData,
    chartColors = listOf(
        MaterialTheme.colors.secondary,
        MaterialTheme.colors.secondary
    ),
    lineColors = listOf(
        MaterialTheme.colors.primary,
        MaterialTheme.colors.primary
    )
)
// Where lineData is
// [LineData(xValue=Oct 27, 2022, yValue=0.0), LineData(xValue=Oct 28, 2022, yValue=0.0), ......]
// the other values have yValue equals to 0

When I run the app, I have the following stacktrace

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ola.myapp, PID: 7867
    java.lang.IllegalArgumentException
        at android.graphics.LinearGradient.nativeCreate(Native Method)
        at android.graphics.LinearGradient.createNativeInstance(LinearGradient.java:158)
        at android.graphics.Shader.getNativeInstance(Shader.java:191)
        at android.graphics.Paint.getNativeInstance(Paint.java:726)
        at android.graphics.BaseRecordingCanvas.drawPath(BaseRecordingCanvas.java:292)
        at androidx.compose.ui.graphics.AndroidCanvas.drawPath(AndroidCanvas.android.kt:242)
        at androidx.compose.ui.graphics.drawscope.CanvasDrawScope.drawPath-GBMwjPU(CanvasDrawScope.kt:473)
        at androidx.compose.ui.node.LayoutNodeDrawScope.drawPath-GBMwjPU(Unknown Source:26)
        at androidx.compose.ui.graphics.drawscope.DrawScope.drawPath-GBMwjPU$default(DrawScope.kt:800)
        at com.himanshoe.charty.line.CurveLineChartKt$CurveLineChart$5.invoke(CurveLineChart.kt:187)
        at com.himanshoe.charty.line.CurveLineChartKt$CurveLineChart$5.invoke(CurveLineChart.kt:112)
        at androidx.compose.ui.draw.DrawBackgroundModifier.draw(DrawModifier.kt:104)
        at androidx.compose.ui.node.DrawEntity.draw(DrawEntity.kt:98)
        at androidx.compose.ui.node.LayoutNodeDrawScope.drawContent(LayoutNodeDrawScope.kt:46)
        at androidx.compose.ui.draw.DrawBackgroundModifier.draw(DrawModifier.kt:105)
        at androidx.compose.ui.node.DrawEntity.draw(DrawEntity.kt:98)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:316)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:306)
        at androidx.compose.ui.node.ModifiedLayoutNode.performDraw(ModifiedLayoutNode.kt:139)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:314)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:306)
        at androidx.compose.ui.node.ModifiedLayoutNode.performDraw(ModifiedLayoutNode.kt:139)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:314)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:306)
        at androidx.compose.ui.node.ModifiedLayoutNode.performDraw(ModifiedLayoutNode.kt:139)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:314)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:306)
        at androidx.compose.ui.node.ModifiedLayoutNode.performDraw(ModifiedLayoutNode.kt:139)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:314)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:306)
        at androidx.compose.ui.node.ModifiedLayoutNode.performDraw(ModifiedLayoutNode.kt:139)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:314)
        at androidx.compose.ui.node.LayoutNodeWrapper.draw(LayoutNodeWrapper.kt:306)
        at androidx.compose.ui.node.LayoutNode.draw$ui_release(LayoutNode.kt:839)
        at androidx.compose.ui.node.InnerPlaceable.performDraw(InnerPlaceable.kt:90)
        at androidx.compose.ui.node.LayoutNodeWrapper.drawContainedDrawModifiers(LayoutNodeWrapper.kt:314)
        at androidx.compose.ui.node.LayoutNodeWrapper.access$drawContainedDrawModifiers(LayoutNodeWrapper.kt:60)
        at androidx.compose.ui.node.LayoutNodeWrapper$invoke$1.invoke(LayoutNodeWrapper.kt:336)
        at androidx.compose.ui.node.LayoutNodeWrapper$invoke$1.invoke(LayoutNodeWrapper.kt:335)
        at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2101)
        at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:110)
        at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:78)
        at androidx.compose.ui.node.LayoutNodeWrapper.invoke(LayoutNodeWrapper.kt:335)
        at androidx.compose.ui.node.LayoutNodeWrapper.invoke(LayoutNodeWrapper.kt:60)
        at androidx.compose.ui.platform.RenderNodeApi29.record(RenderNodeApi29.android.kt:180)

It looks like this error is related to the gradient but I get the same error even if I pass one color to the chart when using lineColor and chartColor

@hi-manshu hi-manshu added the bug Something isn't working label Nov 3, 2022
@hi-manshu
Copy link
Owner

Hey thanks for letting me know will check!

@Ola-jed
Copy link
Author

Ola-jed commented Nov 3, 2022

I have done some tests and i have noticed that this error appears when all the values are 0

@armanTabib
Copy link

armanTabib commented Mar 17, 2024

@Ola-jed
This is part of my data and this bug happens:
Edit:
The strings are empty and thats why it happens.
image

Though it still happens when I set :

chartColors = CurvedLineChartColors(
                        backgroundColors = if(marketCapChange.value > 0) listOf(Color(0xFF218842), Color(0xFF218842)) else listOf(Color(0xffFCEEEE), Color(0xffFCEEEE))
                    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants