I have been using the following code on tick charts for some time to detect the click position / time. Today, I overlayed a 5 minute bar series in the same window, and the code now returns the wrong time...
// convert e.GetPosition for different dpi settings
clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartPanel as IInputElement).X, ChartControl.PresentationSource);
clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartPanel as IInputElement).Y, ChartControl.PresentationSource);
double slotIndex = 0;
if (clickPoint.Y > 0)
{
slotIndex = ChartControl.GetSlotIndexByX((int)clickPoint.X);
if (Time.IsValidDataPointAt((int)slotIndex) && slotIndex > 0 && slotIndex < Bars.Count) // make sure we have a valid data point
{
Print("button clicked on bar " + slotIndex.ToString() + " date is " + Time.GetValueAt((int)slotIndex).ToString());
GetData(Time.GetValueAt((int)slotIndex), DateTime.Now, slotIndex);
} else {
Print("Slotindex invalid? : " + slotIndex.ToString());
}
}
}
Any hints on how I might make this work with multiple bar series in same window? My times are way too short when the 5 minute series is on there. If I remove it, all works as expected again. Is there a way to force this to a specific data series?
Thanks.
Comment