infinum/flutter-charts

Specifying range of values on axis

modelD-svg opened this issue · 1 comments

Hello,

I have gotten a mostly satisfying result using the line-chart-example and customizing it. However, I would like to specify the range of values shown at the horizontal axis, meaning when I have data ranging from 17-27, I would only like to draw the chart in this range and not from 0-27. I have checked HorizontalAxisDecoration and GridDecoration for an option but can't find an option. I tried scaling the values down to 0-10 and then using horizontalAxisValueFromValue, to scale them back up to 17-27. Fells kinda hacky -- is this the intended way?

Also if that's the case, how do I make the chart show 27 as the highest value on the axis, if the highest value in the data is only 25, for example. Do I have to create a dummy-line with value 27 and show it with transparency 0 or something like that?

Thanks!

I tried scaling the values down to 0-10 and then using horizontalAxisValueFromValue, to scale them back up to 17-27. Fells kinda hacky -- is this the intended way?

This is also the first idea that came to my mind.

I wouldn't say it's hacky. There are so many different use cases and various charts, and for some, you need to add a little manual calculation to get the desired result.
For example, you could have used WidgetDecoration and that would then require even more manual calculations but that's the intended way.

Obviously, we could add a parameter to specify the range. But if we were to add a parameter for every possible case, that would probably mean HorizontalDecoration would grow to have 40 parameters and good luck learning how to use that.

Does that make any sense?

how do I make the chart show 27 as the highest value on the axis, if the highest value in the data is only 25, for example

We have that parameter and it's even documented in README. In line with the previous topic, you can see how it can be hard to get to know all the different parameters that exist 😄

Take a look at ChartData(..., valueAxisOverMax: 2).