我有一个带OxyPlot的坐标系。在该坐标系中生成不同的点。现在我很乐意通过按钮询问点数,是否有可能再次阅读积分?这些点显示在坐标系中。
这是例如获取点列表(点始终包含X和Y值) 我之后的列表(或任何解决方案)可以查询,所有点都接收到此坐标系中指示的内容。
图片应该更清楚我想要的是什么。
我有一个坐标系,在此坐标系中显示之前生成的点。现在我想把坐标系中的这些点变成列表或类似的东西。
答案 0 :(得分:1)
这是一个监听 public string UpdatedTime { get; set; }
(您需要更改它)并显示包含所需信息的窗口的工作示例。请注意,您可以在不同的控件中显示结果列表框,例如Popup。
plotModel.MouseDown
您需要以下风格
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.
}
}
使用以下转换器:
<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>
您可以更改DataPoint在此转换器中转换为字符串的方式。