Stripline On MouseClick

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


3 Replies

YP Yuvaraj Palanisamy Syncfusion Team July 21, 2021 01:03 PM UTC

Hi Amitabha, 
 
Greetings from Syncfusion. 
 
You can achieve your requirement “Show Stripline while click on the datapoint and then select another datapoint removed the old one” by using the ChartRegionClick event and Stripline support in chart control. Please find the code example below.  
 
CodeSnippet: 
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); 
    } 
} 
 
Also, we have attached the sample for your reference. Please find the sample from the below link. 
 
  
Output: 
 
 
 
Regards, 
Yuvaraj. 



AM Amitabha July 23, 2021 08:53 PM UTC

Hi Yuvaraj ,


Thank you so much. It Helped me to sort out the issue raised.


Thanks,

Amit



YP Yuvaraj Palanisamy Syncfusion Team July 25, 2021 05:58 AM UTC

Hi Amitabha,

Thank you for your update.

Please let us know if you have any further assistance on this.
 
  
Regards, 
Yuvaraj 


Loader.
Up arrow icon