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:
- Pass list of values to items() inside of the LazyRow()
- For each item, calculate the starting and ending points
- Use Canvas inside of that “item” scope to draw a line from starting to ending point
- 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: