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

Scaling graph given large data set #192

Closed
projectuniverse opened this issue Mar 2, 2023 · 9 comments
Closed

Scaling graph given large data set #192

projectuniverse opened this issue Mar 2, 2023 · 9 comments

Comments

@projectuniverse
Copy link

projectuniverse commented Mar 2, 2023

Hello,

I am using vico with compose and material 3. I am wondering how to scale a line chart with a large data set (about 60-720 data points on average). If I leave the chart at default settings, having hundreds of data points means scrolling endlessly. I have read through some issues, and I came across a solution to disabling horizontal scrolling using chartScrollSpec = rememberChartScrollSpec(isScrollEnabled = false). However, with hundreds of data points, this results in a graph that can't be read anymore (you cannot distinguish the data points, and the tick labels aren't shown - even though I limited the amount of ticks to 10 at max). So this brings me to my question:

Is there a way to customize the spacing between data points on the x-axis (i.e., change the default spacing)?

My goal: I would like the graph to try to show the whole dataset, even with hundreds of data points, without making the user scroll (thus, I need to change the spacing). However, the graph should also be scrollable so that when the data set is too large for it to be properly displayed, the graph is not cramped together. In case the user has to scroll, I would like to limit the amount of scrolls to a minimum.

Thanks for any help!

@patrickmichalik
Copy link
Member

patrickmichalik commented Mar 2, 2023

Hello! HorizontalAxis.TickPosition.Center lets you customize the label spacing. To customize the segment width, you can change the point size (LineChart.LineSpec#pointSizeDp) and point spacing (LineChart#spacingDp).

@tobbyd
Copy link

tobbyd commented Mar 3, 2023

Thanks for the quick reply above! I had the exact same question.

With the default settings, the scaling is also not sufficient for my data :( My data set is even much larger: 7500 entries, where I would like to display a subset of about 500-750 entries at a time on screen - still being able to zoom in until a subset of 50 entries is displayed... Very similar to the request above. Will the library handle such large data sets?

Is there a way, to specify the initial zoom state? Currently, with my test data sets (about 500 entries) I have to zoom out manually quite long, and still cannot see the whole data because there seems to be a limit:

screenshot

@patrickmichalik
Copy link
Member

The initial zoom factor (which is 1) can’t be changed, @tobbyd, because the segment width is customizable. If you were to set the segment width to something around 1 dp, you’d end up having several hundred entries visible initially. Admittedly, though, Vico’s APIs weren’t designed with such charts in mind. We’d be happy to better accommodate such use cases—please feel free to share your suggestions.

@projectuniverse
Copy link
Author

Thanks for the reply! Adjusting the spacing and pointSize did the trick. However, I noticed that setting the pointSize overrides the ChartStyle for the given graph.

@patrickmichalik
Copy link
Member

Hmm, that shouldn’t happen, @projectuniverse. Could you share your code?

@projectuniverse
Copy link
Author

Well I pass the ProvideChartStyle function a Chart where I set the chart parameter to
chart = lineChart(lines = listOf(LineChart.LineSpec(pointSizeDp = 1f))).

@patrickmichalik
Copy link
Member

Got it. Because you’re creating a new LineChart.LineSpec instance instead of copying the appropriate default one, the default styles are lost. Please try this solution. Since you have only one line in your chart, you can use listOf(defaultLines.first().copy(pointSize = 1.dp)) inside remember, skipping the mapping.

@projectuniverse
Copy link
Author

Thanks a lot!

@patrickmichalik
Copy link
Member

You’re welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants