Double Line Series Plot with 2 Y axes

Oystein Bjorke 4 years ago 0
This discussion was imported from CodePlex

bball0246 wrote at 2013-02-18 17:47:

I was looking to make a graph with two line series. The series have drastically different Y ranges so I was wondering whether it would be possible to make two Y axes, one on the left and one on the right. Thanks.

ivarstange wrote at 2013-02-19 10:16:

Yes, this is possible:
var pm = new PlotModel();
var secondaryAxis = new LinearAxis(AxisPosition.Left, "Secondary"); // And add other axes as well
pm.Axes.Add(secondaryAxis); // Add them all
var ls = new LineSeries("Secondary Line");
// Do stuff to add datapoints here
secondaryAxis.Key = "Secondary";
ls.YAxisKey = "Secondary";
Edit: Typo

ivarstange wrote at 2013-02-19 10:43:

I notice, however, that when you zoom or pan, the secondary axis won't update. I haven't figured out how to fix this yet.

bball0246 wrote at 2013-02-19 20:46:

Thanks that is what I needed. It would be nice if they panned and zoomed proportionately to each other but I guess I can deal with that. Is there a way of associating the line series with either axis (color-coding perhaps)?

bball0246 wrote at 2013-02-19 21:14:

The line series can be associated with the axis by color:
secondaryAxis.TicklineColor = OxyColors.Red;
secondaryAxis.TitleColor = OxyColors.Red;
secondaryAxis.TextColor = OxyColors.Red;
ls.Color = OxyColors.Red;
Still working on the zoom/pan issue.

bball0246 wrote at 2013-02-19 21:28:

Both axes are independent so each one has to be zoomed independently. By default (I don't know if this can be changed), the left axis is the one that has control when the mouse is over the graph. To control the right axis, you have to hover over it and scroll to zoom or right-click drag to pan.

ivarstange wrote at 2013-02-19 21:39:

I noticed the same thing. It can be useful (sometimes) to control them independently. I believe that most people would want the (ctrl+RMB)-zoom to function as if they were dependent/connected, and that they could be independently controlled if the mouse was over the axis. (But this is another discussion, I guess)

urm3l wrote at 2013-04-03 23:59:

Not sure if you still need an answer to the proportional zooming but maybe someone else will.

You can work around the issue of the independent axes with following the example of the coupled axes, But instead of using the actualMaximum of the other axis you are computing a proportion factor with the two maxima of your plots. Then you can scale the actualMaximum with that factor.

Its a little trickier to do that for the mimima as well but it should work.
CodePlex