infinum / flutter-charts

Customizable charts library for flutter.
https://pub.dev/packages/charts_painter
MIT License
144 stars 42 forks source link

WidgetItemOptions cannot have set item width #77

Closed nicklohuis closed 1 year ago

nicklohuis commented 1 year ago

Setting the width of the Widget returned from widgetItemBuilder will not increase the width of the item.

The goal of the chart is to have a scrollable 7 item view with custom bar widgets, the inserted list of values is over 2000 items so the bars get squished so small they disappear.

how can i use my own bar widget implementation and set the amount of items to show in the chart?

nicklohuis commented 1 year ago

Below a recreation of the result i get, this is a scrollable widget chart with 104 items. I would like to be able to tell the scrollable chart how many items i want in view, this should sort out the widget width aswell, if not i'd like to be able to set the widget width and have the amount of items in view be sorted out by that. Is this possible and am i looking in the wrong way or is this not possible yet?

Screenshot 2023-01-04 at 11 17 36
lukaknezic commented 1 year ago

Hey @nicklohuis. I checked this out and yes it looks like there is a issue with the new WidgetItemOptions this is not working as intended. I will look into it and fix that. Changing WidgetItemOptions with BarItemOptions and setting minBarWidth you should get what you want. (Also don't forget to set isScrollable to true in ChartBehaviour)

You can also then calculate the width of the chart, divide by nubmer you want (7) and pass that number to minBarWidth to make sure that only that number (7) of items are visible at the same time.

Hope that helps for now, I will respond here once I fix the issue with WidgetItemOptions

nicklohuis commented 1 year ago

Hi @lukaknezic, Thanks for the quick response, using BarItemOptions won't let me use my own widget layout for each bar, thats why i tried to use WidgetItemOptions, if the issue-fix will solve the squishing of the items and lets them be the set width defined in the custom widget that would solve my issue. I can use BarItemOptions to see the data visualised, but not yet as i wish, i'll test the fix as soon as it is available. Again thanks for the help.

lukaknezic commented 1 year ago

Yeah I figured that out, this is just a fix to show them while I work on actual fix 😄

But I tried just adding minBarWidth to WidgetItemOptions and looks like that does it. It's in separate branch now I will run more tests on it and add tests to cover that case before merging.

You can try the fix by adding that branch to your pubspec:

charts_painter:
  git: 
    url: https://github.com/infinum/flutter-charts
    ref: fix/widget-options
nicklohuis commented 1 year ago

that seems to work great, thanks