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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Adding Padding to both end of Xaxis.

Thread ID:





59074 Apr 4,2007 02:27 PM UTC Apr 12,2007 01:18 PM UTC WinForms 3
Tags: Chart
Hongbin Zhang
Asked On April 4, 2007 02:27 PM UTC


I am trying to add paddings to the both ends of the Xaxis, so the beginning and the end labels and data points could display. I see the paddings were added to the graph, but the labels on the XAxis are off, should start at Jan-06, and end at Sep-06, the grid also doesn't line up with the lable. Here is the code snippet, can you advise what I should do to get this right?

public void paddingXAxis(double offset, ChartControl myChart, ChartDateTimeIntervalType intervalType, int interval, string xaxisFormat)
DateTime dateMin=DateTime.Now,dateMax=DateTime.Now;
int dataCount = myChart.Series[0].SeriesModelImpl.Count;

if (dataCount > 0)
dateMin = DateTime.FromOADate(myChart.Series[0].SeriesModelImpl.GetX(0));
dateMax = DateTime.FromOADate(myChart.Series[0].SeriesModelImpl.GetX(dataCount-1));
int monthDiff = dateMax.Month - dateMin.Month;
int yrDiff = dateMax.Year - dateMin.Year;

if(yrDiff > 0)
monthDiff = monthDiff + 12*yrDiff;

case ChartDateTimeIntervalType.Days: break;
case ChartDateTimeIntervalType.Months:
myChart.PrimaryXAxis.Offset = offset;
myChart.PrimaryXAxis.Range.Max += 2 * offset;
for(int i = 0; i <= monthDiff; i+=interval)
ChartAxisLabel lable = new ChartAxisLabel(i.ToString(), Color.Black, new Font("Arial",10,FontStyle.Bold), dateMin, xaxisFormat,xaxisFormat);



Rajesh C [Syncfusion]
Replied On April 6, 2007 06:35 AM UTC


Thank you for your interest in Syncfusion Products.

Please try to apply following code snippet for adding the paddings to the both ends of the axis.

[ C# ]

private void PaddingBothEnd(ChartAxis axis, double offset)

double min = axis.Range.Min ;
double max =axis.Range.Max ;
double interval = axis.Range.Interval;


axis.Range.Min -= (interval*offset );
axis.Range.Max += (interval*offset );

axis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode ;
if (axis.ValueType == ChartValueType.DateTime)
for(double i=min;i<=max;i+=interval)
axis.Labels.Add(new ChartAxisLabel(DateTime.FromOADate (i).ToString(axis.DateTimeFormat) , Color.Black , new Font("Times New Roman", 12), i, "", ChartValueType.Custom));
if (axis.ValueType == ChartValueType.Double)
for (double i = min; i <= max; i += interval)
axis.Labels.Add(new ChartAxisLabel(i.ToString(), Color.Black, new Font("Times New Roman", 12), i, "", ChartValueType.Custom));


Please have a look at this sample and let me know if this helps you.



Hongbin Zhang
Replied On April 10, 2007 05:55 PM UTC

Hi Rajesh,

It works using the code you provided. Many thanks!

can you also take a look at the other issue that the data point doesn't line up with the bar, I tried the way you suggested, but it didn't work.


Ramya R [Syncfusion]
Replied On April 12, 2007 01:18 PM UTC


I have updated your query regarding data point doesn't line up with the bar in the Forum-#59033 which you posted with regard to this query.

Kindly refer the update in that forum.

Thanks & Regards,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon