Hi,
I am trying to draw a vertical stripline on mouseclick on a chart. The stripline will be drawn on the datapoint clicked. Each time a new datapoint on chart is clicked the stripline will appear on the clicked datapoint and any previous stripline drawn earlier will be wiped off. I tried below. But its not producing the desired result. Firstof All its not plotting at the correct candle(datapoint) on first click and secondly on subsequent click its not updating to the newly clicked Candle(datapoint). And Can you please check and let me know why its not working as expected.
NOTE: My X_axis is of Category Type.
private void Sfchart_Price_ChartRegionClick(object sender, ChartRegionMouseEventArgs e)
{
ChartPoint Cp = sfchart_Price.ChartArea.GetValueByPoint(e.Point);
SelectedCnldIdx = e.Region.PointIndex;
Draw_SelectedCandle();
}
public void Draw_SelectedCandle()
{
if (SelectedCnldIdx != -1)
{
sfchart_Price.PrimaryXAxis.StripLines.Clear();
ChartStripLine stripLine = new ChartStripLine();
stripLine.Enabled = true;
stripLine.Vertical = true;
stripLine.Period = SelectedCnldIdx + 1;
stripLine.Start = sfchart_Price.ChartArea.PrimaryYAxis.Range.Min;
stripLine.End = sfchart_Price.ChartArea.PrimaryYAxis.Range.Max;
stripLine.Width = 0.3;
stripLine.Interior = new BrushInfo(230, new BrushInfo(GradientStyle.Vertical, Color.OrangeRed, Color.DarkKhaki));
sfchart_Price.PrimaryXAxis.StripLines.Add(stripLine);
}
}
Thanks,
Amitabha
|
this.chartControl1.ChartRegionClick += ChartControl1_ChartRegionClick;
int selectedIndex = -1;
private void ChartControl1_ChartRegionClick(object sender, ChartRegionMouseEventArgs e)
{
selectedIndex = e.Region.PointIndex;
Draw_SelectedCandle();
}
public void Draw_SelectedCandle()
{
if (selectedIndex != -1)
{
this.chartControl1.PrimaryXAxis.StripLines.Clear();
ChartStripLine stripLine = new ChartStripLine();
stripLine.Enabled = true;
stripLine.Vertical = true;
stripLine.Text = "";
stripLine.Period = selectedIndex + 1; // We need only one datapoint hence the stripline period extend by 1 for category type.
stripLine.Start = selectedIndex - 0.5; //Start the stripline before half part of datapoint index
stripLine.End = selectedIndex + 0.5; //Stripline ends after half part of the datapoint.
stripLine.Interior = new BrushInfo(230, new BrushInfo(GradientStyle.Vertical, Color.OrangeRed, Color.DarkKhaki));
this.chartControl1.PrimaryXAxis.StripLines.Add(stripLine);
}
} |
Hi Yuvaraj ,
Thank you so much. It Helped me to sort out the issue raised.
Thanks,
Amit