Custom draw axis labels

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

nicolasr75 wrote at 2013-09-10 22:20:

Hello all,

I really appreciate the possibility to have four y-axes using the PositionTier property (two axes on the left and two on the right)
My problem is that the user can not tell to which axis a specific series is bound.

Does anyone have experience how to solve this?

A friend suggested I should have small, colored squares behind the axis titles to indicate the associated series.
But this would require that I custom draw the axis titles? Any idea how to do this?

thanks in advance!
Nicolas

everytimer wrote at 2013-09-10 22:41:

I think the easiest solution is a variation of your friend's suggestion. But instead marking the axes, distinguish the series with different styles: you can choose from LineStyle (Solid, Dot, Dash, and combinations), LineThickness, Color, and Markers. You could also use the Title to indicate which axis owns the Series. To make things clearer for the user you should add a custom Legend with indications. Other solution could be to create two Lists of OxyColors with Red/Blue tones (for example). Then choose appropriate color for your axes. Good luck.

objo wrote at 2013-09-11 20:21:

@nicolasr75: interesting question!

It is possible to subclass the axis and override the rendering, but I see the HorizontalAndVerticalAxisRenderer need some refactoring to make it easier (the RenderAxisTitle method is not overridable).

@everytimer: good suggestion, note also that the color of the axis title can be set to match the series that use the axis

See also
https://oxyplot.codeplex.com/workitem/9192

nicolasr75 wrote at 2013-09-11 20:35:

Many thanks to you both!

@everytimer: very interesting ideas, I will think about them and do some tests with it...

@objo: so you say it is in principle possible to render the axis myself? Could you give me a hint which classes in which files implement the original rendering?
Maybe an intermediate solution would be to duplicate the code in my derived class. By the way: this is for maximally four vertical axes and currently only for WPF.

Nicolas

objo wrote at 2013-09-11 20:43:

Override the Render method. You see the current implementation in Axis.cs
Your derived class will work on all platforms.

nicolasr75 wrote at 2013-09-11 20:52:

Thanks for the quick reply (and of course for this awesome component!)
Nicolas

objo wrote at 2013-09-11 21:14:

I submitted some changes that should make it easier to override the axis rendering classes. Note that these classes should be refactored later and then you may need to do some changes in your code (that's why I try to keep the public/protected API to a minimum...)

nicolasr75 wrote at 2013-09-12 00:04:

Thanks for the changes.

For a first try I have derived special implementations from LinearAxis and HorizontalAndVerticalRenderer.
I have overridden the Render methods and call the base classes methods. After that I call my rendering code for colored rectangles that represent the associated series. I had to use Reflection to get at some internal properties of the Axis class though.
This seems to work fine for now!

thanks again for your help!