[英]How do you bind a specific Color of a specific column within an OxyPlot LinearBarSeries in XAML in a c# WPF project?
Any help here is appreciated: I would like to associate through binding in XAML (or some other method as long as it works) a specific bar column color to data in my bar series.感谢这里的任何帮助:我想通过 XAML 中的绑定(或其他一些方法,只要它有效)将特定的条形列颜色与我的条形系列中的数据相关联。 Ultimately, I would like to have one color per column item.
最终,我希望每个列项目有一种颜色。 I suspect color attribute could be added to the class where the column item data value is stored.
我怀疑可以将颜色属性添加到存储列项目数据值的类中。 So far, by default, all I get is the same color for every bar column in my graph...very boring to say the least - you'd think all bar series plotting utilities can change the color of any one column in a bar series right?!
到目前为止,默认情况下,我得到的只是图表中每个条形列的颜色相同......至少可以说很无聊 - 您会认为所有条形系列绘图实用程序都可以更改条形中任何一列的颜色系列对吗?! If OxyPlot can do it - I haven't found the solution yet.
如果 OxyPlot 可以做到 - 我还没有找到解决方案。
I tried to create a custom Style to see if I could gain some insight into the LinearBarSeries class, but it was vague.我尝试创建一个自定义 Style 以查看是否可以深入了解 LinearBarSeries 类,但它很模糊。 I then looked inside these classes: DataPointSeries, DataPoint, ColumnItem,ColumnSeries, and BarItemBase, but I'm more confused than ever.
然后我查看了这些类:DataPointSeries、DataPoint、ColumnItem、ColumnSeries 和 BarItemBase,但我比以往任何时候都更加困惑。
My XAML so looks like this and basically it comes from the example provided by OxyPlot's LinearBarSeries example:我的 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&L" DataFieldX="Time" DataFieldY="Value" FillColor="#454CAF50" StrokeColor="#4CAF50" StrokeThickness="1" BarWidth="5">
</oxy:LinearBarSeries>
</oxy:Plot>
</DockPanel>
</Window>
So far I have no method to change column item color for any data column.到目前为止,我无法更改任何数据列的列项目颜色。 Please help if you can, Thanks!
可以的话请帮忙,谢谢!
I found it easier to use a PlotModel
for OxyPlot customization as in我发现使用
PlotModel
进行 OxyPlot 定制更容易,如
<oxyWpf:Plot Model="{Binding PlotModel}" />
Thus you can add multiple Series
with different colours and add your data to it:因此,您可以添加多个具有不同颜色的
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});
There should be plenty of samples at OxyPlot's GitHub repository or other resources. OxyPlot 的 GitHub 存储库或其他资源中应该有大量示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.