Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] kotlin – Is there a way to make a scrollable chart in JetPack Compose?

Posted on November 11, 2022 By

Solution 1 :

To make your Canvas horizontally scrollable you just need to set width and horizontalScroll modifier like below:

Canvas(
    modifier = Modifier
        .horizontalScroll(rememberScrollState())
        .width(2000.dp)
        .height(300.dp)
) { 
   // ...
}

Problem :

So, I have a very simple graph defined through Canvas. I want to make this graph scrollable (horizontally).

I know that I can make scrollable lists through LazyRow/LazyColumn. My current “thought” process looks like this: “I can create LazyRow and use my list of values to draw a line inside of each “item” of LazyRow.”

In other words the algorithm would be something like that:

  1. Pass list of values to items() inside of the LazyRow()
  2. For each item, calculate the starting and ending points
  3. Use Canvas inside of that “item” scope to draw a line from starting to ending point
  4. Repeat from 2 until all lines are drawn

Even though I haven’t coded it yet, I’m pretty sure this “approach” will work… However it looks a bit over-complicated…

I thought, maybe, it could be possible to just draw the whole chart and make it scrollable through modifier or something like that. I looked at API documentation for Compose Canvas, Modifier and etc. but I couldn’t find something useful to me… probably I’m blind.

Comments

Comment posted by example of scrollable and zoomable chart

example of scrollable and zoomable chart

Comment posted by stackoverflow.com/questions/72565488/…

@vitidev would you follow the same approach if you need to scroll on both axes? I believe that’d also solve my problem here:

READ  [FIXED] java - Updating specific firebase field using recyclerview button in android
Powered by Inline Related Posts
Android Tags:android-jetpack-compose, kotlin

Post navigation

Previous Post: [FIXED] java – is permission needed when choosing image from gallery on android?
Next Post: [FIXED] Android Java: How to get component in a custom view? (Trying to access components via findByViewId and get null)

Related Posts

[FIXED] java – How can i fix “Emulator: Process finished with exit code -2147483645” on android studio? Android
[FIXED] android – Running an Activity that requires permission to access the gallery Android
[FIXED] java – Android studio get data from html and filter only some value to show on textView Android
[FIXED] java – Firebase Auth problem regarding phone authentication Android
[FIXED] xamarin.android – Visual Studio for Mac – System.InvalidOperationException: Resource not found: wear-frame-round-390.png Android
[FIXED] android – Using adb monkey seed across different devices/emulators Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme