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. 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.
I tried to create a custom Style to see if I could gain some insight into the LinearBarSeries class, but it was vague. I then looked inside these classes: DataPointSeries, DataPoint, ColumnItem,ColumnSeries, and BarItemBase, but I'm more confused than ever.
My XAML so looks like this and basically it comes from the example provided by OxyPlot's LinearBarSeries example:
<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
<oxyWpf:Plot Model="{Binding PlotModel}" />
Thus you can add multiple Series
with different colours and add your data to it:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.