We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Windows Forms Chart Plotting Minor Grid Lines with a Log Scale

It appears that there are no methods to plot minor grid lines. It can be accomplished using the ChartAreaPaint event. The code below shows an example.
 

Private

Sub _BubblePlot_ChartAreaPaint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles _BubblePlot.ChartAreaPaint

Dim YMin As Double, YMax As Double, XMin As Double, XMax As Double, MaxStop As Double

Dim GridLoc As Double, _Increment As Double

Dim _Pen As Pen = New Pen(System.Drawing.Color.FromArgb(175, 129, 115, 27))

 

If (_BubblePlot.PrimaryYAxis.ValueType = ChartValueType.Logarithmic) Then 'Include Minor Gridlines for Y Axis (Horizontal)

Dim ptLeft As Point, ptRight As Point

YMin = _BubblePlot.PrimaryYAxis.Range.Min

'Min, Max Values in Log Space

YMax = _BubblePlot.PrimaryYAxis.Range.Max

MaxStop = 10 ^ YMax

Dim LogIncrement As Integer = CInt(YMin)

_Increment = 10 ^ YMin

GridLoc = _Increment

'> Draw horizonal lines incrementing by _Increment for each log cycle

Do While GridLoc < MaxStop

For I As Integer = 1 To 9

GridLoc += _Increment

ptLeft = _BubblePlot.ChartArea.GetPointByValue(

New ChartPoint(_BubblePlot.PrimaryXAxis.Range.Min, GridLoc))

ptRight = _BubblePlot.ChartArea.GetPointByValue(

New ChartPoint(_BubblePlot.PrimaryXAxis.Range.Max, GridLoc))

e.Graphics.DrawLine(_Pen, ptLeft.X, ptLeft.Y, ptRight.X, ptRight.Y)

Next

_Increment *= 10

GridLoc = _Increment

Loop

End If

If (_BubblePlot.PrimaryXAxis.ValueType = ChartValueType.Logarithmic) Then 'Include Minor Gridlines for X Axis (Vertical)

Dim ptBottom As Point, ptTop As Point

XMin = _BubblePlot.PrimaryXAxis.Range.Min

'Min, Max Values in Log Space

XMax = _BubblePlot.PrimaryXAxis.Range.Max

MaxStop = 10 ^ YMax

Dim LogIncrement As Integer = CInt(XMin)

_Increment = 10 ^ XMin

GridLoc = _Increment

'> Draw horizonal lines incrementing by _Icrement for each log cycle

Do While GridLoc < MaxStop

For I As Integer = 1 To 9

GridLoc += _Increment

ptBottom = _BubblePlot.ChartArea.GetPointByValue(

New ChartPoint(GridLoc, _BubblePlot.PrimaryYAxis.Range.Min))

ptTop = _BubblePlot.ChartArea.GetPointByValue(

New ChartPoint(GridLoc, _BubblePlot.PrimaryXAxis.Range.Max))

e.Graphics.DrawLine(_Pen, ptBottom.X, ptBottom.Y, ptTop.X, ptTop.Y)

Next

_Increment *= 10

GridLoc = _Increment

Loop

End If

End Sub


1 Reply

VK Vijayabharathi K Syncfusion Team August 15, 2012 08:37 AM UTC

Hi Bruce,

 Thanks for using Syncfusion products.

 We are having properties to plot the minor grid lines in logarithmic type chart. Please refer the below code snippet to achieve this,

 [C#]

this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.Logarithmic;

            this.chartControl1.PrimaryXAxis.DrawMinorGrid = true;

            this.chartControl1.PrimaryXAxis.SmallTicksPerInterval = 3;

 Note: Please find the attachment screenshot for minor grid lines.

 Please let us know if any concerns.

 Regards,

Vijayabharathi

 



Screenshot_e83d19d5.zip

Loader.
Live Chat Icon For mobile
Up arrow icon