How to set MajorGridLine interval for LogarithmicAxis at 10%?

Hi, I would like to have the gridline spacing at 10% (or 5%, 2%, 1%, etc.) for the SecondaryAxis which is of type LogarithmicAxis. I've tried changing the LogarithmicBase and setting the Interval to 0.1, but can't get the spacing to be exactly 10%. So for example, if a gridline is at 87, the next gridline above should be at 87 * 1.1 = 95.7. It doesn't matter at what level the gridlines start or end. Also, in the final version the SecondaryAxis labels will be collapsed. How can this be achieved?

The attached sample can be used to modify.

Thank you.

Attachment: sfChartGridlineTest_321cd687.rar

3 Replies

MK Muneesh Kumar G Syncfusion Team May 11, 2018 12:13 PM UTC

Hi Tom, 
 
We have analyzed your requirement, we can add labels at custom position by overriding GenerateVisibleLabels method and add the labels at required indexes. 
 
Code snippet: 
Protected Overrides Sub GenerateVisibleLabels() 
         
        Dim position As Double = VisibleRange.Start - VisibleRange.Start Mod Interval 
 
        Do While (position <= VisibleRange.End) 
 
            If (VisibleRange.Inside(position)) Then 
 
               'ChartAxisLabel(Position, DisplayValue, ActualValue) 
                Dim axisLabel = New ChartAxisLabel(position, 
                                   Math.Round(Math.Pow(LogarithmicBase, 
                                   Math.Log((Math.Pow(LogBase, position)),   
                                   LogarithmicBase))), position) 
 
                VisibleLabels.Add(axisLabel) 
 
            End If 
 
            position = position + Interval 
        Loop 
 
    End Sub 
 
We have modified our sample based on this, please find the sample from the following location.  
 
 
Output :  
 
 
 
Please let us know if you have any queries.  
 
Thanks, 
Muneesh Kumar G. 
 



TO Tom May 11, 2018 04:45 PM UTC

Hi Muneesh, what you've done is simply to round out the numbers, the spacing is the same as before.

However, you've pointed out the connection between the display y values and the internal position value, so what I've done is to reverse your formula so that we can set the gridline spacing according to the display value:

  Protected Overrides Sub GenerateVisibleLabels()

        Dim YvalInterval As Double = 10 'this is the percent interval for the gridlines
        Dim Yval As Double 'this is the price value we want to set the gridline to
        Dim pos As Double 'this is the internal position value we need to set the gridline to
        Dim base = Me.LogarithmicBase

        'GET THE FIRST YVAL
        pos = VisibleRange.Start
        Dim exponent = Math.Log((Math.Pow(base, pos)), base)
        Yval = Math.Pow(base, exponent)

        'CREATE GRIDLINES
        Do

            If (VisibleRange.Inside(pos)) Then
                VisibleLabels.Add(New ChartAxisLabel(pos, Yval, pos))    'ChartAxisLabel(Position, DisplayContent, ActualValue)
            End If

            Yval = Yval * (1 + YvalInterval / 100) 'set the next Yval
            Dim b = Math.Log(Yval, base)
            pos = Math.Log(Math.Pow(base, b), base) 'get the internal position value for the next gridline

        Loop While (pos <= VisibleRange.End)

    End Sub

With this, the issue is resolved.

Thanks.


MK Muneesh Kumar G Syncfusion Team May 14, 2018 05:42 AM UTC

Hi Tom,

Thanks for the update.

We are glad to know that the given solution works. Please let us know if you need any further assistance.

Thanks,
Muneesh Kumar G. 


Loader.
Up arrow icon