Page 1 of 1
.NET2 plotting vertical line on datetime series
Posted: Wed Apr 18, 2007 7:47 am
by 9640436
Hi,
I would some advice to plot a vertical line on a datetime line series to indicate the current datetime. So this line will cut across the x-axis (the datetime axis) at where the current date is.
I'm using C# btw.
Thanks.
Posted: Wed Apr 18, 2007 9:36 am
by 9348258
Hi Dave
You have two possibilities to draw this. The first and easier is using a "ColorLine" Tool, can be something similar as below code:
Code: Select all
private ColorLine colorLine1;
private void Form1_Load(object sender, EventArgs e)
{
tChart1.Aspect.View3D = false;
colorLine1 = new ColorLine(tChart1.Chart);
colorLine1.Active = true;
colorLine1.AllowDrag = true;
colorLine1.Axis = tChart1.Axes.Bottom;
colorLine1.AllowDrag = false; //If you want that user can't move the ColorLine
line1.Add(DateTime.Parse("16/04/2007"), 4);
line1.Add(DateTime.Parse("17/04/2007"), 3);
line1.Add(DateTime.Parse("18/04/2007"), 7);
line1.Add(DateTime.Parse("19/04/2007"), 8);
line1.Add(DateTime.Parse("20/04/2007"), 5);
line1.Add(DateTime.Parse("21/04/2007"), 2);
colorLine1.Value = DateTime.Today.ToOADate();
}
The second possibility, is to draw a line on the canvas of chart. You should do it in the "AfterDraw" event as below code:
Code: Select all
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
Point s = new Point(line1.CalcXPosValue(DateTime.Today.ToOADate()), tChart1.Axes.Left.IStartPos - 10);
Point e = new Point(line1.CalcXPosValue(DateTime.Today.ToOADate()), tChart1.Axes.Bottom.Position + 10);
g.Line(s, e);
}
Posted: Thu Apr 19, 2007 2:46 am
by 9640436
Thanks Edu, I managed to get it to work. I decided to go with the ColorLine option.
BTW, is it possible to display the x-axis value that the ColorLine intersects? I am considering allowing users to drag the line and it'll display the datetime that the line intersects.
Posted: Thu Apr 19, 2007 8:11 am
by 9348258
Hi Dave
You can use the "DragLine" ColorLine event to do it, as below code:
Code: Select all
colorLine1.DragLine += new EventHandler(colorLine1_DragLine);
void colorLine1_DragLine(object sender, EventArgs e)
{
tChart1.Header.Text = "Date: " + DateTime.FromOADate(colorLine1.Value).ToString();
}
Posted: Mon Apr 23, 2007 5:21 am
by 9640436
Thanks Edu.
Posted: Wed May 09, 2007 6:21 am
by 9640436
Hi Edu,
I notice that when I use ColorLine, the line could be plotted outside the vertical axis. For example, when I set have
Code: Select all
colorLine1.Value = DateTime.Today.ToOADate();
but the vertical axis contains date before the colorLine1.Value date, the line is plotted on the right hand side of the right vertical axis. Is there a way I can limit ColorLine to only show up within the period in the horizontal axis?
Posted: Wed May 09, 2007 10:09 am
by 9348258
Hi Dave
ColorLine has got the "NoLimitDrag" property, if you put it to true, the ColorLine can be draw out of axis range. Also can be interesting to you, to hide the ColorLine when is out of range. You can do something similar as below code:
Code: Select all
colorLine1.NoLimitDrag = true;
//Below code, hide the tool when is out of range
private void tChart1_Scroll_1(object sender, EventArgs e)
{
for (int i = 0; i < tChart1.Tools.Count; i++)
{
if (tChart1.Tools[i] is Steema.TeeChart.Tools.ColorLine) SetActiveColorLine(i);
}
}
private void SetActiveColorLine(int i)
{
Steema.TeeChart.Tools.ColorLine tmpColorLine = (Steema.TeeChart.Tools.ColorLine)tChart1.Tools[i];
if ((tmpColorLine.Value > tmpColorLine.Axis.Maximum) || (tmpColorLine.Value < tmpColorLine.Axis.Minimum))
tmpColorLine.Active = false;
else
tmpColorLine.Active = true;
}
Other possibility can be disables the tool, when is out of range:
Posted: Wed May 09, 2007 11:27 pm
by 9640436
Thanks Edu, I checked it against Axis.MaxXValue & Axis.MinXValue and it works.
Cheers!