We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Ticklines at 7 days interval and fixed at the beginning of each week in DateTimeAxis

Hi,

Thanks for great charting library.

I'd like to fix the DateTimeAxis intervals to always begin on Monday, so that ticklines would illustrate the beginning of the week in my 60 days chart. Is that possible?

DateTimeAxis(
      intervalType: DateTimeIntervalType.days,
      interval: 7,
      maximum: last,
      minimum: 60,
);

3 Replies

DD Dharanidharan Dharmasivam Syncfusion Team December 16, 2019 12:38 AM

Hi Pasi, 
 
Thanks for trying out our Flutter widgets and your feedback. Your requirement can be achieved by specifying the minimum range to the x-axis. We have prepared a sample in which we have found the first occurrence of Monday from the data source and specified that date to the minimum range for x-axis. Also, we have specified the interval as 7, so that the chart always shows the beginning of the week. You can change this based on your scenario, find the code snippet below to achieve this. 
 
 
@override 
  void initState() { 
    for (int i = 1; i < 29; i++) { 
      chartData.add(_ChartData( 
          DateTime(201912, i), (min + random.nextInt(max - min)).toDouble())); 
      // Found the first day of the week 
      if (xMinimum == null && 
          DateFormat('EEEE').format(DateTime(201912, i)) == 'Monday') 
        xMinimum = DateTime(201912, i); 
    } 
     
  } 
 
SfCartesianChart( 
            primaryXAxis: DateTimeAxis( 
              // Set the range here 
                minimum: xMinimum, 
                interval: 7, 
                intervalType: DateTimeIntervalType.days), 
            // Other configurations 
         ), 
 
 
 
The sample can be found from the below link. 
 
Thanks, 
Dharani. 



PA Pasi December 16, 2019 08:39 AM

Great, thanks for your fast response and idea. 
I'll look into it and check if it behaves correctly also when zooming and when the data range is wide e.g. > 365 days or so.



DD Dharanidharan Dharmasivam Syncfusion Team December 16, 2019 11:33 PM

Hi Pasi, 

Thanks for the revert. We will wait to hear from you. 

Thanks, 
Dharani. 


Loader.
Live Chat Icon For mobile
Up arrow icon