Hello Kirti,
According to the provided information, I understand that you have RadChartView with CandleStickSeries that plots its data on the DateTimeCategorical axis for the horizontal axis and Linear axis for the vertical axis. Your requirement is to get the value from the horizontal axis when there is an interaction with the mouse.
In order to achieve this, I used an "onePixelTime" variable that shows how many ticks a single pixel of the chart represents. It can also be helpful when the view is zoomed to a particular date range. In the MouseDown event, the exact location is calculated. Please refer to the following example:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
CandlestickSeries candlestickSeries;
public RadForm1()
{
InitializeComponent();
this.radChartView1.MouseDown += this.RadChartView1_MouseDown;
candlestickSeries = new CandlestickSeries();
candlestickSeries.DataPoints.Add(new OhlcDataPoint(10, 11, 7, 8, DateTime.Now));
candlestickSeries.DataPoints.Add(new OhlcDataPoint(8, 9, 5, 9, DateTime.Now.AddDays(1)));
candlestickSeries.DataPoints.Add(new OhlcDataPoint(12, 12, 9, 10, DateTime.Now.AddDays(2)));
candlestickSeries.DataPoints.Add(new OhlcDataPoint(7, 10, 6, 9, DateTime.Now.AddDays(3)));
this.radChartView1.Series.Add(candlestickSeries);
}
double onePixelTime = 0;
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
var first = (OhlcDataPoint)candlestickSeries.DataPoints[0];
var last = (OhlcDataPoint)candlestickSeries.DataPoints[candlestickSeries.DataPoints.Count - 1];
TimeSpan span = (DateTime)last.Category - (DateTime)first.Category;
double totalWidth = last.LayoutSlot.X + last.LayoutSlot.Width / 2 - first.LayoutSlot.X - first.LayoutSlot.Width / 2;
this.onePixelTime = span.Ticks / totalWidth;
}
private void RadChartView1_MouseDown(object sender, MouseEventArgs e)
{
IChartView view = this.radChartView1.View;
var firstDataPoint = (OhlcDataPoint)candlestickSeries.DataPoints[0];
var offset = this.radChartView1.Area.View.Viewport.X + firstDataPoint.LayoutSlot.X + firstDataPoint.LayoutSlot.Width / 2;
double location = e.Location.X - offset - view.PlotOriginX;
long ticks = (long)(location * this.onePixelTime / view.ZoomWidth);
TimeSpan span = TimeSpan.FromTicks(ticks);
DateTime startDate = (DateTime)firstDataPoint.Category;
DateTime clickedDate = startDate.Add(span);
Console.WriteLine(clickedDate);
}
}
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way that suits your requirements best.
Another approach that I would like to note is that RadChartView offers trackball behavior. It can display a vertical line across the chart plot area and also to display little visual indicators (circles by default) at points where the trackball line crosses the visualization of a series object. More information on this topic you can find here.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Nadya
Progress Telerik
Progress is here for your business, like always.
Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.