I'm using OxyPlot in my WPF project to create a plot with two Y axes. I have different series assigned to either the left or the right Y axis. I would like to display two separate legends: one on the left with elements corresponding to the left Y axis, and another legend for the right Y axis.
I have already implemented the two Y axes and assigned the series correctly to each axis using the YAxisKey property. However, I haven't found a built-in way to split the legends in OxyPlot.
Is there a way to achieve this visual separation of legends? If so, could you please provide guidance or an example of how to implement it?
My current code for creating the axes and series assignment looks similar to the following:
var leftAxis = new LinearAxis
{
Position = AxisPosition.Left,
Key = "LeftAxis",
Title = "Left Axis"
};
var rightAxis = new LinearAxis
{
Position = AxisPosition.Right,
Key = "RightAxis",
Title = "Right Axis"
};
plotModel.Axes.Add(leftAxis);
plotModel.Axes.Add(rightAxis);
var series0 = new LineSeries
{
YAxisKey = rightAxis.Key,
Title = "Series0",
Color = OxyColors.Blue,
};
var series1 = new LineSeries
{
YAxisKey = leftAxis.Key,
Title = "Series0",
Color = OxyColors.Red,
};
I'm open to any suggestions or alternative approaches to visually split the legends based on the Y axes. Thank you in advance for your help!
You can add an arbitrary number of legends to a
PlotModel. Each instance ofLegendcan get it's own key assigned. You can then set theLegendKeyproperty on each series to control in which legend they are displayed.