infinum / flutter-charts

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

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

Closed 978740431 closed 3 years ago

978740431 commented 3 years ago

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

lukaknezic commented 3 years ago

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 😄

978740431 commented 3 years ago

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

lukaknezic commented 3 years ago

Great 🎉 Okay, thanks for input. I'll add that to readme and maybe some examples 😃

roly151 commented 3 years ago

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