我正在使用WPF中的OxyPlot并且有一些问题。我试图创建一个应用程序,并希望使用OxyPlot创建图表。一切正常,但情节/数据不会显示出来。我似乎无法弄清楚为什么。在WPF中创建一个OxyPlot
下面是我的一些XAML代码:
<UserControl x:Class="myNameSpace.MainPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:app="clr-namespace:myNameSpace"
xmlns:oxy="http://oxyplot.org/wpf"
mc:Ignorable="d"
d:DesignHeight="1200"
d:DesignWidth="1920">
<UserControl.DataContext>
<local:MainViewModel/>
</UserControl.DataContext>
....
<oxy:Plot Title="{Binding Title}" Margin="760,689,606,228" Width="504" Height="283">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding Points}"/>
</oxy:Plot.Series>
</oxy:Plot>
和我MainViewPanel类看起来是这样的:
public class MainViewModel
{
public MainViewModel()
{
this.Title = "Example 2";
this.Points = new List<DataPoint>
{
new DataPoint(0, 4),
new DataPoint(10, 13),
new DataPoint(20, 15),
new DataPoint(30, 16),
new DataPoint(40, 12),
new DataPoint(50, 12)
};
}
public string Title { get; private set; }
public IList<DataPoint> Points { get; private set; }
}
这是图表的外观,当我运行我的代码就像
您提供的代码对我来说工作正常。这是一个外部的机会,但我认为VM中的Points列表是OxyPlot.DataPoint的列表,而不是其他地方的DataPoint列表。 –
忽略我以前的评论,再次看看你的照片,它看起来像标题不具约束力。 –
您确定您的xaml中引用的MainViewModel是正确的类型。我没有看到定义的本地命名空间前缀。如果MainViewModel位于AnnaEmilie命名空间中,请将本地:MainViewModel更改为app:MainViewModel –