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.
Unfortunately, activation email could not send to your email. Please try again.

Adding Padding to both end of Xaxis.

Thread ID:

Created:

Updated:

Platform:

Replies:

59074 Apr 4,2007 10:27 AM Apr 12,2007 09:18 AM Windows Forms 3
loading
Tags: Chart
Hongbin Zhang
Asked On April 4, 2007 10:27 AM

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

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

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

Hongbin Zhang
Replied On April 10, 2007 01:55 PM

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

Ramya R [Syncfusion]
Replied On April 12, 2007 09:18 AM

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.

CONFIRMATION

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.

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.

;