[英]Read coordinates from OxyPlot
I have a coordinate system with OxyPlot. 我有一个OxyPlot坐标系。 Different points are generated in this coordinate system.
在此坐标系中生成了不同的点。 Now I would gladly ask the points by button, is it possible to read the points again?
现在,我很乐意通过按钮询问要点,是否可以再次阅读要点? The points are displayed in the coordinate system.
点显示在坐标系中。
This is eg Get a list of the points (a point always contains an X and a Y value) Which I afterwards the list (or whatever the solution is) can query and all points receive the indicated in this coordinate system. 例如,这是获取点的列表(一个点始终包含X和Y值),之后我可以查询列表(或任何解决方案),并且所有点都将收到此坐标系中指示的点。
The picture should make more clear what I would like. 图片应该更清楚我想要什么。
I have a coordinate system and in this coordinate system points are displayed which were generated before. 我有一个坐标系,在此坐标系中显示了以前生成的点。 Now I want to get these points from the coordinate system into a list or something similar.
现在,我想将这些点从坐标系中获取到列表或类似内容中。
This is a working example which listens to plotModel.MouseDown
(You need to change it) and displays a window with the required information. 这是一个工作示例,它侦听
plotModel.MouseDown
(您需要对其进行更改)并显示一个包含所需信息的窗口。 Note that you can display the resulted listbox in different Controls such as Popup. 请注意,您可以在不同的控件(如弹出窗口)中显示结果列表框。
public partial class MainWindow : Window
{
PlotModel plotModel;
public MainWindow()
{
InitializeComponent();
plotModel = new PlotModel { Title = "OxyPlot" };
plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom });
plotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, Maximum = 10, Minimum = 0 });
var series1 = new OxyPlot.Series.LineSeries
{
MarkerType = MarkerType.Circle,
MarkerSize = 5,
MarkerStroke = OxyColors.White
};
series1.Points.Add(new DataPoint(0, 6));
series1.Points.Add(new DataPoint(1, 2));
series1.Points.Add(new DataPoint(2, 4));
series1.Points.Add(new DataPoint(3, 2));
series1.Points.Add(new DataPoint(4, 7));
series1.Points.Add(new DataPoint(6, 6));
series1.Points.Add(new DataPoint(8, 8));
series1.Smooth = true;
plotModel.Series.Add(series1);
this.Content = new OxyPlot.Wpf.PlotView() { Model = plotModel };
plotModel.MouseDown += PlotModel_MouseDown;
}
private void PlotModel_MouseDown(object sender, OxyMouseDownEventArgs e)
{
var s = plotModel.Series[0] as LineSeries; // asuming that there is just one line series
ListBox list = new ListBox();
list.Style = (Style)TryFindResource("listOfPoint");
list.ItemsSource = s.Points;
Window win = new Window() { Content = list, Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; // You can display the results in a Popup too
win.ShowDialog(); // You might call Show() instead.
}
}
You need the following style 您需要以下样式
<Window.Resources>
<local:DataPointToStringConverter x:Key="DataPointToStringConverter"/>
<Style x:Key="listOfPoint" TargetType="ListBox">
<Setter Property="AlternationCount" Value="1000"/>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate >
<StackPanel Orientation="Horizontal">
<TextBlock >
<TextBlock.Text>
<MultiBinding Converter="{StaticResource DataPointToStringConverter}">
<Binding />
<Binding Path="ItemsSource" RelativeSource="{RelativeSource AncestorType=ListBox, Mode=FindAncestor}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
Which uses the following converter: 使用以下转换器:
public class DataPointToStringConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
DataPoint point = (DataPoint)values[0];
List<DataPoint> points = ((IEnumerable<DataPoint>)values[1]).ToList();
return (points.IndexOf(point) + 1).ToString() +"- (" + point.X.ToString() + " , " + point.Y.ToString() + ")";
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
You can change how DataPoint is converted into a string in this converter. 您可以更改在此转换器中将DataPoint转换为字符串的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.