Jeremy Johnson,
I recommend you two solutions for solve your problem in your code.
First, you can set ColorLine AllowDrag property to true as do in next lines of code:
Code: Select all
var line = new ColorLine(tChart1.Chart)
{
Axis = tChart1.Axes.Bottom,
Pen = { Style = DashStyles.Solid, Color = Colors.Red, Width = 1 },
Value = Utils.DateTime(DateTime.Now),
AllowDrag = true
};
Previous code do that ColorLine isn't drawn out of bounds of chart.
Second, you can define a limit for the ColorLines aren't drawn out of bounds of Chart.
Code: Select all
public MainWindow()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
FastLine fastLine1 = new FastLine(tChart1.Chart);
var line = new ColorLine(tChart1.Chart)
{
Axis = tChart1.Axes.Bottom,
Pen = { Style = DashStyles.Solid, Color = Colors.Red, Width = 1 },
AllowDrag = false
};
tChart1.Aspect.View3D = false;
tChart1.Header.Font.Bold = true;
tChart1.Header.Font.Size = 15;
fastLine1.FillSampleValues();
fastLine1.LinePen.Width = 1;
tChart1.AfterDraw += tChart1_AfterDraw;
}
void tChart1_AfterDraw(object sender, Graphics3D g)
{
for (int i = 0; i < tChart1.Tools.Count; i++)
{
Steema.TeeChart.WPF.Tools.Tool tool = tChart1.Tools[i];
if (tool is Steema.TeeChart.WPF.Tools.ColorLine)
{
if ((tool as Steema.TeeChart.WPF.Tools.ColorLine).Value < tChart1.Axes.Bottom.Minimum || (tool as Steema.TeeChart.WPF.Tools.ColorLine).Value > tChart1.Axes.Bottom.Maximum)
{
tool.Active = false;
}
else
{
tool.Active = true;
}
}
}
}
Could you tell us if my suggestions help you to solve the problem?
I hope will helps.
Thanks,