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

x axis custom labels and grid

Thread ID:

Created:

Updated:

Platform:

Replies:

75532 Jul 29,2008 03:39 PM UTC Sep 10,2008 06:45 AM UTC WinForms 3
loading
Tags: Chart
Administrator [Syncfusion]
Asked On July 29, 2008 03:39 PM UTC

hi,

is there any way how to customize labels and grids on x axis? i mean when start date of axis is set to 3.1.2008 12.35 then i'd like to keep it as start date, but would like to show user labels and grids based on some sensible values - so it means that the first label and vertical line should be drawn e.g. on 3.1.2008 13:00 and next e.g. 1 hour later.

thanks in advance
Lubos


J.Nagarajan [Syncfusion]
Replied On August 12, 2008 07:43 AM UTC

Hi Lubos,

Thanks for your interest in Syncufsion products.

We can display custom labels at certain dates along the X axis by using the ChartFormatAxisLabel event of the ChartControl. Please refer to the below code snippet.

this.chartControl1.ChartFormatAxisLabel += new ChartFormatAxisLabelEventHandler(chartControl1_ChartFormatAxisLabel);
//To add custom text to labels
void chartControl1_ChartFormatAxisLabel(object sender, ChartFormatAxisLabelEventArgs e)
{
if (e.IsAxisPrimary && e.AxisOrientation == ChartOrientation.Horizontal)
{
switch (e.ValueAsDate.ToString("d"))
{
case "11/8/2003":
e.Label = "11/8/2003/13:00";
break;
case "11/15/2003":
e.Label = "11/8/2003/14:00";
break;
}
}
}

Here is the working sample.

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

Please refer to it and let me know if this helps.

Thanks,
Nagaraj


Administrator [Syncfusion]
Replied On September 1, 2008 06:15 AM UTC

hi,

thanks for the answer, but i probably asked wrong way... i needn't modify label but i need to move the label (+ grid) to the sensible position. is it what your code does?

thanks
Lubos


Manohari [Syncfusion]
Replied On September 10, 2008 06:45 AM UTC

Hi Lubos,

We regret very much for the delayed response. Please find our responses to your queries below.

1) It is possible to move the Axis lines and labels to a specified values by specifying the offset value to the axis. ChartAxis.Offset will move the axis according to the value specified.

Sample code:

this.chartControl1.PrimaryXAxis.DateTimeOffset = new TimeSpan(60); // for DateTime values
this.chartControl1.PrimaryXAxis.Offset = 5; // for Double values

2) It is also possible to draw custom Labels and Grid at the specified position by using the ChartAreaPaint event.

Sample code:

this.chartControl1.ChartAreaPaint += new PaintEventHandler(chartControl1_ChartAreaPaint);
}

void chartControl1_ChartAreaPaint(object sender, PaintEventArgs e)
{
if (showCustomGridLines)
{
float minX = this.chartControl1.ChartArea.RenderBounds.Left;
...
...
for (int i = 0; i < intervals; i++)
{ ...
...
ChartPoint cp = new ChartPoint(dt, 0);
float x = (float)this.chartControl1.ChartArea.GetPointByValue(cp).X;
float y = this.chartControl1.ChartArea.RenderBounds.Bottom;
if (x >= minX && x <= maxX)
{

PointF pnt = new PointF(x, y + this.chartControl1.PrimaryXAxis.TickSize.Height);
e.Graphics.DrawString(dateX, this.chartControl1.PrimaryXAxis.Font, new SolidBrush(Color.Blue), new PointF(x - (sz.Width / 2), y + this.chartControl1.PrimaryXAxis.TickSize.Height + 4 + (sz.Height / 2))); // To Draw Labels
Pen p = new Pen(Color.FromArgb(0, 0, 255));
e.Graphics.DrawLine(Pens.Blue, new PointF(x, y), new PointF(x, y + this.chartControl1.PrimaryXAxis.TickSize.Height)); // To Draw Ticks
e.Graphics.DrawLine(p, new PointF(x, this.chartControl1.ChartArea.RenderBounds.Bottom), new PointF(x, this.chartControl1.ChartArea.RenderBounds.Top));
}
....
....

I have attached the sample that illustrates the above two methods in this link below.

http://websamples.syncfusion.com/samples/Chart.Windows/F75532/Sample1.htm

Kindly let us know if this meets your requirements. Thanks for your patience.

Regards,
Manohari.R




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.

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

;