簡體   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