【问题标题】:Assigning two y-axes to two lineseries in oxyplot (C# WPF)在oxyplot(C#WPF)中将两个y轴分配给两个lineseries
【发布时间】:2017-10-16 00:43:17
【问题描述】:

我已经在低位和高位搜索了这个问题的答案,但我只找到了与 Windows 窗体相关的旧答案,而不是 WPF。文档中没有提到任何内容。

我有两个使用oxyplot 绘制的线条系列。但是,我无法将每个系列分配给单独的轴(由于比例不同,我需要两个轴)。

在找到的示例中,声明应将 key="somename" 分配给轴定义,并将 YAxisKey="somename" 分配给行系列。但是,我收到一条错误消息,指出这些属性不存在。任何帮助是极大的赞赏。请参阅下面附加的 xaml 代码

<Wpf:Plot    
    DockPanel.Dock="Bottom"
    x:Name="OxyPlot1" 
    Title="{Binding Title}" Height="400" Margin="0,0,0,0">

    <Wpf:Plot.Axes>        
        <Wpf:LinearAxis
            x:Name="Psiaxis" Position="Left" Title="Pressure (PSI)"
            TickStyle="Inside" StartPosition="0"/>
        <Wpf:LinearAxis
            x:Name="Gpmaxis" Position="Right" Title="Flow In (GPM)"
            TickStyle="Inside" StartPosition="0"/>
        <Wpf:DateTimeAxis
            Position="Bottom" TickStyle="Inside" IntervalType="Seconds" 
            MinorGridlineStyle="Dash" MajorGridlineStyle="Solid"
            StringFormat="dd:MM:yyyy HH:mm:ss"/>
        </Wpf:Plot.Axes>

        <Wpf:LineSeries 
            x:Name="SelectedPointsPressure"
            Height="100" 
            Width="100" 
            Title="Pressure (psi)"
            ItemsSource="{Binding ToPlotPoints1}"/>

        <Wpf:LineSeries
            x:Name="RegressionPoints"
            Height="100"
            Width="100"
            LineStyle="Solid"
            Color="Blue"
            Title="Linear least squares fit"
            ItemsSource="{Binding ToPlotPoints2}"/>

        <Wpf:LineSeries 
            x:Name="SelectedPointsFlowin"
            Height="100" 
            Width="100" 
            LineStyle="Solid"
            Color="Green"
            Title="Flow In (gpm)"
            ItemsSource="{Binding ToPlotPoints3}"/>
    </Wpf:Plot>

【问题讨论】:

    标签: c# wpf axis axes oxyplot


    【解决方案1】:

    您必须为每个 Y 轴定义关键属性。

    <oxyWpf:LinearAxis x:Name="Psiaxis" Position="Left" 
            Title="Pressure (PSI)" TickStyle="Inside" StartPosition="0"  Key="Psiaxis"   />
    

    因此,您可以设置 YAxisKey

    <oxyWpf:LineSeries
            x:Name="RegressionPoints"
            Height="100"
                YAxisKey="Psiaxis"
            Width="100"
            LineStyle="Solid"
            Color="Blue"
            Title="Linear least squares fit"
            ItemsSource="{Binding PointsSeries2}"/>
    

    【讨论】:

    • 感谢您的快速“跟进”,这正是我尝试过的,但是对于“关键”视觉工作室,在将鼠标悬停在“关键”上时给我以下错误消息:属性'在“LinearAxis”类型中找不到键。无法解析符号键。当悬停在 =“Psiaxis” 上时,它告诉我:成员“Key”未被识别或无法访问。
    • 你用的是什么oxyplot版本?我使用 OxyPlot.Wpf version="1.0.0" 并且 Key 是 OxyPlot.Wpf.Axis 的成员请注意它是 Key 大写字母。
    • 我有一个预发布版本。我用 nuget 将其删除并安装了 1.0.0。现在他们 "Key=""" 等工作,但是,我在尝试构建解决方案时收到此错误消息: FileLoadException: Could not load file or assembly 'OxyPlot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=638079a8f0bd61e9 ' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 例外:0x80131040)我尝试重新安装该版本,但没有任何帮助。还从 nuget/references 添加/删除。有什么想法吗?
    • 通过删除解决方案文件夹中“app”文件中对“oxyplot”的引用,解决了上述内部异常问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多