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

Adding Padding to both end of Xaxis.

Hi,

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;

switch(intervalType)
{
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);
myChart.PrimaryXAxis.Labels.Add(lable);
dateMin.AddMonths(interval);
}
}
break;
}
}

thanks,
HB



lineChartIssue.zip

3 Replies

RC Rajesh C Syncfusion Team April 6, 2007 06:35 AM UTC

Hi,

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.Labels.Clear();

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));
else
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.

http://websamples.syncfusion.com/samples/Chart.Windows/F59974/main.htm

Regards,
Rajesh


HZ Hongbin Zhang 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.

Thanks,
HB


RR Ramya R Syncfusion Team April 12, 2007 01:18 PM UTC

Hi,

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,
Ramya.

Loader.
Live Chat Icon For mobile
Up arrow icon