locked
Logaritmic scale not possible RRS feed

  • Question

  • On a form i have placed a chart1.

    When i execute these lines (at load):

     Form_Spettro.Chart1.ChartAreas(0).AxisX.Minimum = 1
     Form_Spettro.Chart1.ChartAreas(0).AxisX.Maximum = Fs / 4
     Form_Spettro.Chart1.ChartAreas(0).AxisX.IsLogarithmic = True
     Form_Spettro.ShowDialog()

     I get an error: System.InvalidOperationException, related to graph axes, saying that logaritmic scale is not possible.

    I do not know why.

    Thursday, January 30, 2020 10:08 PM

Answers

  • Thanks, now it works.

    You have to draw some line after initialization:

    With Chart1.ChartAreas(0)
                .AxisX.Title = "Hz"
                .AxisX.IsLogarithmic = True
                .AxisX.LogarithmBase = 10
    End With

            'This is mandatory 
            For n = 1 To N_samples / 4
                Me.Chart1.Series(0).Points.AddXY(n, X_s(n))
            Next

    X_s(n) is the signal to show. Variable n must begin from 1 or more. After these lines, you can draw other series of data.

    Thanks tommytwotrain for help.

    You are welcome.

    To close the thread and help others in the future, please indicate the post(s) that answered your question using the "Mark as Answer" link at the bottom of the reply.


    Saturday, February 1, 2020 9:28 AM

All replies

  • Out of curiosity, do you get this error on one specific chart type? Have you tried it on a different chart type? Seems if I remember not all charts support logarithmic scaling. 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, January 30, 2020 10:25 PM
  • Hy Karen.

    What do you mean for different chart type?

    If i set x axys logaritmic directly on the form, it appears logaritmic.

    Thursday, January 30, 2020 11:47 PM
  • There is not enough info given to reproduce the problem?

    One thing is it has to be valid data ie you cant plot strings, dates, zero values, etc.

    Here is a working example. Can you produce the problem by changing this code? Or give a complete working example?

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            With Chart1.ChartAreas(0)
                .AxisX.Interval = 2
                .AxisX.Title = "X"
                .AxisY.Title = "Y Log Base 10"
                .AxisY.IsLogarithmic = True
                .AxisY.LogarithmBase = 10
            End With
    
            Chart1.Series.Clear()
            Chart1.Series.Add("")
    
            With Chart1.Series(0)
                .IsVisibleInLegend = False
                .ChartType = DataVisualization.Charting.SeriesChartType.Line
    
                Dim y As Single
    
                For x = 1 To 10
                    y = CSng(0.3 * x * x)
                    .Points.AddXY(x, y)
                Next
    
            End With
        End Sub
    End Class

    Friday, January 31, 2020 11:02 AM
  • Thanks, now it works.

    You have to draw some line after initialization:

    With Chart1.ChartAreas(0)
                .AxisX.Title = "Hz"
                .AxisX.IsLogarithmic = True
                .AxisX.LogarithmBase = 10
    End With

            'This is mandatory 
            For n = 1 To N_samples / 4
                Me.Chart1.Series(0).Points.AddXY(n, X_s(n))
            Next

    X_s(n) is the signal to show. Variable n must begin from 1 or more. After these lines, you can draw other series of data.

    Thanks tommytwotrain for help.

    Friday, January 31, 2020 8:25 PM
  • Thanks, now it works.

    You have to draw some line after initialization:

    With Chart1.ChartAreas(0)
                .AxisX.Title = "Hz"
                .AxisX.IsLogarithmic = True
                .AxisX.LogarithmBase = 10
    End With

            'This is mandatory 
            For n = 1 To N_samples / 4
                Me.Chart1.Series(0).Points.AddXY(n, X_s(n))
            Next

    X_s(n) is the signal to show. Variable n must begin from 1 or more. After these lines, you can draw other series of data.

    Thanks tommytwotrain for help.

    You are welcome.

    To close the thread and help others in the future, please indicate the post(s) that answered your question using the "Mark as Answer" link at the bottom of the reply.


    Saturday, February 1, 2020 9:28 AM