我正在使用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 –