Eventhough I set major tick frequency for x-axis(date-time-axis), labels are not adjusted to that frequency (5)



I am having a problem with x-axis labels. I am setting the x-axis major frequency to either 1 month or 3 months. But, when the chart is rendered, number of labels are decreasing. For example, I want to view the chart for 1 year with a major tick frequency of 30days. That means, chart needs to display 12 labels on x-axis. But, this is not happening. It is automatically adjusting to greater frequency and only few labels are visible instead of 12. Can someone help me in solving out the issue. This is for ios.



Can someone reply to this,please?


Hello Manish,

The first property you should look at for this is the majorTickFrequency which controls the frequency at which the ticks appear. 

xAxis.majorTickFrequency = SChartDateFrequency.dateFrequencyWithMonth(1)

However if there is not enough room to display all of the ticks at the interval you have specified, the chart will default to the next best frequency that works. In this instance you have three properties you can use. 

  • labelFormatString - you can use this to reduce the format of what you’re trying to display, for example “MMM” would display “Jan”, “Feb”, “Mar” rather than the default of “Jan 16”, “Feb 16”, “Mar 16”.
  • minimumFreeAxisSpace - this is the percentage of padding present between tick labels, by default it is set at 1% (0.01), you could reduce this to create extra space. 
  • labelFont (style.majorTickStyle.labelFont) - you can use this to change the font size of the tick labels

Bringing them all together by doing something like (and changing the values to suit your aims):

xAxis.majorTickFrequency = SChartDateFrequency.dateFrequencyWithMonth(1)
xAxis.labelFormatString = "MMM"
xAxis.minimumFreeAxisSpace = 0
xAxis.style.majorTickStyle.labelFont = UIFont.systemFontOfSize(8)

You should be able to achieve what you are aiming for. 

Kind regards,

Matt Webber