Custom tick labels

Oystein Bjorke 6 aastat tagasi uuendaja Dwayne Heibroch Petersen 5 aastat tagasi 1
This discussion was imported from CodePlex

danielmda wrote at 2013-08-08 07:42:

I need to plot some numeric data as a function of audio frequency. The frequency axis (x axis) is in octave bands - which is base 2 log. Here's an example I found online of what I want to plot:
The picture is not very good quality, the frequency values are: 63, 125, 250, 500, 1k, 2k, 4k, 8k Hz.

I can't seem to be able to create such an axis. I've tried a few things without success:
  1. Using log axis for frequency - but the values are calculated with a reference of 1. That means values count up as so: 1, 2, 4, 8, 16... etc. I need a way to set a custom reference (e.g. 1000 Hz) so I can start at 63 (or 62.5) and work my way up from there.
  2. Using a category axis for frequency, so I can specify a custom string - but I need the labels to line up with the grid lines, not in between the grid lines (if that makes sense?)
  3. Using a linear axis for frequency - but I see no way of replacing the numeric labels with custom strings.
Does anyone have any ideas? It seems like I need VS2012 (I have 2010) to open and compile the source, so I really am stuck. I think option 1. should be quite easy to implement?

WeirdNoise wrote at 2013-08-11 17:59:

You could just override the LogarithmicAxis.GetTickValues() without recompiling oxyplot as I did here.

A hacky, but nonetheless working, example (in VB I'm afraid):
Public Class MyLogAxis
    Inherits Axes.LogarithmicAxis

    Public Overrides Sub GetTickValues(ByRef majorLabelValues As IList(Of Double), ByRef majorTickValues As IList(Of Double), ByRef minorTickValues As IList(Of Double))
        majorTickValues = New List(Of Double)

        minorTickValues = majorTickValues
        majorLabelValues = majorTickValues

    End Sub
End Class

danielmda wrote at 2013-08-13 09:00:

Ah, that's awesome. Thank you so much!

I'm looking to customize it further (templating would be a great option). I need to turn the tick marks into buttons with their respective values as the buttons text. Is this possible?