code
private void AddLineAnnotation(ComboBox comboBox, List<Tuple<DateTime, DateTime>> waveList, bool isUpWave)
{
if (comboBox.SelectedItem == null) return;
int selectedIndex = comboBox.SelectedIndex;
if (selectedIndex < 0 || selectedIndex >= waveList.Count) return;
var selectedWave = waveList[selectedIndex];
var startCandlestick = candlestickList.FirstOrDefault(c => c.Date.Date == selectedWave.Item1.Date);
var endCandlestick = candlestickList.FirstOrDefault(c => c.Date.Date == selectedWave.Item2.Date);
if (startCandlestick != null && endCandlestick != null)
{
double startY = isUpWave ? startCandlestick.Low : startCandlestick.High;
double endY = isUpWave ? endCandlestick.High : endCandlestick.Low;
// Create line annotation
var lineAnnotation = new LineAnnotation
{
AxisX = chart1.ChartAreas[0].AxisX,
AxisY = chart1.ChartAreas[0].AxisY,
X = startCandlestick.Date.ToOADate(),
Y = startY,
Width = endCandlestick.Date.ToOADate() - startCandlestick.Date.ToOADate(),
Height = endY - startY,
LineColor = isUpWave ? Color.Green : Color.Red,
LineWidth = 2,
LineDashStyle = ChartDashStyle.Solid,
IsSizeAlwaysRelative = false,
ClipToChartArea = chart1.ChartAreas[0].Name,
Tag = "WaveLine" // add that if x and y are not numbers then use anchor x and anchor y, and it should be set to NAN
};
// Add the line annotation to the chart
chart1.Annotations.Add(lineAnnotation);
// Refresh the chart
chart1.Invalidate();
}
} // this code is not working, help please