Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c#WPF项目中,如何在XAML中绑定OxyPlot LinearBarSeries中特定列的特定颜色?_C#_Wpf_Data Binding_Colors_Oxyplot - Fatal编程技术网

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

在c#WPF项目中,如何在XAML中绑定OxyPlot LinearBarSeries中特定列的特定颜色?,c#,wpf,data-binding,colors,oxyplot,C#,Wpf,Data Binding,Colors,Oxyplot,感谢您的帮助: 我想通过绑定XAML(或其他一些方法,只要它有效)将特定的条列颜色与我的条系列中的数据相关联。最后,我希望每个列项目有一种颜色。我怀疑颜色属性可以添加到存储列项数据值的类中。到目前为止,默认情况下,我得到的是图形中每个条形列的相同颜色…至少可以说非常无聊-你会认为所有条形系列绘图实用程序都可以更改条形系列中任何一列的颜色,对吗?!如果OxyPlot能做到,我还没有找到解决方案 我试图创建一个自定义样式,看看是否可以深入了解LinearBarSeries类,但这是模糊的。然后我查看

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

我试图创建一个自定义样式,看看是否可以深入了解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}" />

应在或其他资源中提供大量样本。

感谢nirr提供PlotModel/LineSeries建议;尽管如此,我仍在研究一种颜色是否可以与ColumnSeries中的一个ColumnItem关联。我明白了。似乎我在OxyPlot版本上落后了很多,但是当使用
ColumnItem
时,它提供了
Color
属性。查看示例,最近甚至删除了
ColumnSeries
,尽管我不确定是否已经发布了此更改。
var blueLineSeries = new LineSeries{Color = OxyColors.Blue};
blueLineSeries.Points.Add(new DataPoint(/*...*/));
PlotModel.Series.Add(blueLineSeries);
PlotModel.Series.Add(new LineSeries{Color = OxyColors.Green});