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.
.NET2 plotting vertical line on datetime series
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:
The second possibility, is to draw a line on the canvas of chart. You should do it in the "AfterDraw" event as below code:
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();
}
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);
}
Hi Dave
You can use the "DragLine" ColorLine event to do it, as below code:
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();
}
Hi Edu,
I notice that when I use ColorLine, the line could be plotted outside the vertical axis. For example, when I set have
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?
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();
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:
Other possibility can be disables the tool, when is out of range:
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;
}
Code: Select all
colorLine1.Active = false;