繁体   English   中英

在WPF中创建OxyPlot

[英]Create an OxyPlot in WPF

我在WPF中使用OxyPlot并遇到一些问题。 我正在尝试创建一个应用程序,并希望使用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; }
     }

这是我运行代码时图表的样子

屏幕截图

我没有看到定义的本地名称空间前缀。 如果MainViewModel位于AnnaEmilie名称空间中,请将local:MainViewModel更改为app:MainViewModel

删除边距,因为它们会遮挡您的图表形式。

<oxy:Plot Title="{Binding Title}" Width="504" Height="283">
    <oxy:Plot.Series>
        <oxy:LineSeries ItemsSource="{Binding Points}"/>
    </oxy:Plot.Series>
</oxy:Plot>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM