infinum/flutter-charts

How do I set the data for the x-axis?

978740431 opened this issue ยท 4 comments

Now the display is 0~N, I want to display the date, how do I need to set

Hey,

With GridDecoration or VerticalAxisDecoration you have valueFromIndex. This is a function that will return you index and you can return any string you want as label text.

Hope that helps ๐Ÿ˜„

Thank you very much, it is ready to use.
I hope there is a case in the demo, because my English and flutter technology is very poor, so after reading your reply I still took some time to solve it, if the case has examples, it will be very good to help sdk users

Great ๐ŸŽ‰
Okay, thanks for input. I'll add that to readme and maybe some examples ๐Ÿ˜ƒ

For anyone looking to do this, here is an example that adds three letter day names to the horizontal axis (starting from today - var now = new DateTime.now();

GridDecoration(
                showHorizontalValues: false,
                showVerticalValues: true,
                verticalAxisValueFromIndex: (int value) {
                      return DateFormat.E().format(now.add(new Duration(days: value))).toString();
                  },
                verticalAxisStep: 1,
                horizontalAxisStep: 3,
                textStyle: TextStyle(color: Colors.grey),
                gridColor: Theme.of(context).dividerColor,
              ),

Screen Shot 2021-10-28 at 10 37 18 pm