Silverlight Toolkit:右键选择图表系列数据项和左键选择图表系列数据项
本文关键字:系列 数据项 选择 Toolkit 右键 Silverlight | 更新日期: 2023-09-27 18:05:15
对不起,如果这是一个新手问题,但是,好吧,我…我已经试着这样做了2天了,搜索网络,询问周围,没有人能帮助我,所以任何见解将被感激…
我基本上需要做的是选择一个图表系列(ColumnSeries或LineSeries)数据点右键,然后我打开一个上下文菜单。当我处理menuItemClick事件时,我需要数据点的x轴值。理想情况下,我希望能够在右键点击和左键点击上引发SelectionChanged事件,但没有找到任何方法来做到这一点。我尝试了一些替代方法,但总是走不通。这个解决方案似乎可以满足我对LineSeries的需求:在Silverlight Toolkit图表中选择最近的点,但是我的90%的系列都是ColumnSeries,没有系列。
最后我使用了这个解决方案:http://www.c-sharpcorner.com/uploadfile/baimey/silverlight-charts-coordinates-on-mousemove/
我想我最好把它贴出来,以防有人需要。
private void Chart_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
Series serie = sender as Series;
DateTime xAxisValue;
Point p = e.GetPosition(serie);
ICategoryAxis xAxis = (CategoryAxis)Chart.ActualAxes[0];
object xHit = xAxis.GetCategoryAtPosition(new UnitValue(p.X, Unit.Pixels));
if (SelectedObj != null)
{
xAxisValue = (DateTime)new DateTimeConverter().ConvertBack(xHit as String, typeof(String), SelectedObj.DisplayFrequency, Thread.CurrentThread.CurrentUICulture);
foreach (Frequency frequency in SelectedObj.Frequencies)
{
if(frequency == SelectedObj.DisplayFrequency)
addMenuItem(frequency, true, xAxisValue);
else
addMenuItem(frequency, false, xAxisValue);
}
cMenu.IsOpen = true;
cMenu.HorizontalOffset = e.GetPosition(LayoutRoot).X;
cMenu.VerticalOffset = e.GetPosition(LayoutRoot).Y;
}
}
private void addMenuItem(Frequency frequency, bool isDisplayFrequency, DateTime xAxisValue)
{
menuItem = new MenuItem();
menuItem.Header = frequency;
menuItem.Tag = xAxisValue;
if (isDisplayFrequency)
{
menuItem.Icon = new TextBlock { Text = "'xfc", FontFamily = new System.Windows.Media.FontFamily("Wingdings"), FontWeight = FontWeights.Bold, TextAlignment = TextAlignment.Center };
menuItem.FontWeight = FontWeights.Bold;
}
cMenu.Items.Add(menuItem);
menuItem.Click += new RoutedEventHandler(menuItem_Click);
}
void menuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem item = sender as MenuItem;
Frequency itemFreq = (Frequency)item.Header;
DateTime xAxisValue = (DateTime)item.Tag;
...
cMenu.IsOpen = false;
}