繁体   English   中英

如何在 ac# WPF 项目中的 XAML 中的 OxyPlot LinearBarSeries 中绑定特定列的特定颜色?

[英]How do you bind a specific Color of a specific column within an OxyPlot LinearBarSeries in XAML in a c# WPF project?

感谢这里的任何帮助:我想通过 XAML 中的绑定(或其他一些方法,只要它有效)将特定的条形列颜色与我的条形系列中的数据相关联。 最终,我希望每个列项目有一种颜色。 我怀疑可以将颜色属性添加到存储列项目数据值的类中。 到目前为止,默认情况下,我得到的只是图表中每个条形列的颜色相同......至少可以说很无聊 - 您会认为所有条形系列绘图实用程序都可以更改条形中任何一列的颜色系列对吗?! 如果 OxyPlot 可以做到 - 我还没有找到解决方案。

我尝试创建一个自定义 Style 以查看是否可以深入了解 LinearBarSeries 类,但它很模糊。 然后我查看了这些类:DataPointSeries、DataPoint、ColumnItem、ColumnSeries 和 BarItemBase,但我比以往任何时候都更加困惑。

我的 XAML 看起来像这样,基本上它来自 OxyPlot 的 LinearBarSeries 示例提供的示例:

<Window>
   <Window.Resources>
      <Style x:Key="LinearBarSeriesStyle1" TargetType="{x:Type oxy:LinearBarSeries}">
         <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="{x:Type oxy:LinearBarSeries}">
                  <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                     <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                  </Border>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </Window.Resources>

    <DockPanel>
        <oxy:Plot Title="LinearBarSeries">
            <oxy:Plot.Annotations>
                <oxy:LineAnnotation Type="Horizontal" Y="0"></oxy:LineAnnotation>
            </oxy:Plot.Annotations>
            <oxy:Plot.Axes>
                <oxy:DateTimeAxis IntervalType="Hours" IntervalLength="50"/>
            </oxy:Plot.Axes>
            <oxy:LinearBarSeries Style="{DynamicResource LinearBarSeriesStyle1}" ItemsSource="{Binding Pnls}" Title="P&amp;L" DataFieldX="Time" DataFieldY="Value" FillColor="#454CAF50" StrokeColor="#4CAF50" StrokeThickness="1" BarWidth="5">

            </oxy:LinearBarSeries>
        </oxy:Plot>
    </DockPanel>
</Window>

到目前为止,我无法更改任何数据列的列项目颜色。 可以的话请帮忙,谢谢!

我发现使用PlotModel进行 OxyPlot 定制更容易,如

<oxyWpf:Plot Model="{Binding PlotModel}" />

因此,您可以添加多个具有不同颜色的Series并将数据添加到其中:

var blueLineSeries = new LineSeries{Color = OxyColors.Blue};
blueLineSeries.Points.Add(new DataPoint(/*...*/));
PlotModel.Series.Add(blueLineSeries);
PlotModel.Series.Add(new LineSeries{Color = OxyColors.Green});

OxyPlot 的 GitHub 存储库或其他资源中应该有大量示例。

暂无
暂无

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

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