Jump to content
Software FX Community

Scale problem for Y axis


Recommended Posts

I provide only two points (0.01, 0.0007) and (1000000, 0.0007) to make a line. The code is simple:


.Chart1.Data.X.Item(0, 0) = 0.01Me.Chart1.Data.X.Item(0, 1) = 1000000

Me.Chart1.Data.Y.Item(0, 0) = 0.0007

Me.Chart1.Data.Y.Item(0, 1) = 0.0007

and set some format:

Me.Chart1.AxisY.LogBase = 10

Me.Chart1.AxisY.LabelsFormat.Format = AxisFormat.ScientificMe.Chart1.AxisY.Min = 0.0006

Me.Chart1.AxisY.Max = 0.0008

Then I got a chart without scale label.  I want the scale label show up, in this case, 0.0007 or some number should display beside Y axis. any idea?  I use VB.NET, thanks.



Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Please post a complete sample. This code produces the desired chart on my end.

Hi Frank,

Here is my complete sample, it is a very simple form:


ChartFX.WinFormsPublic Class Form1



Region " Windows Form Designer generated code "Public Sub New()MyBase.New()


'This call is required by the Windows Form Designer.


'Add any initialization after the InitializeComponent() call

End SubPublic Sub New(ByVal theTitle As String, ByVal yLableFormat As String)MyBase.New()


'This call is required by the Windows Form Designer.


'Add any initialization after the InitializeComponent() callMe.Text = theTitle

End Sub

'Form overrides dispose to clean up the component list.Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then


End If

End IfMyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

'Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.Friend WithEvents Chart1 As ChartFX.WinForms.Chart


Private Sub InitializeComponent()Dim TitleDockable1 As ChartFX.WinForms.TitleDockable = New ChartFX.WinForms.TitleDockable

Me.Chart1 = New ChartFX.WinForms.ChartCType(Me.Chart1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout()



'Me.Chart1.Location = New System.Drawing.Point(16, 8)

Me.Chart1.Name = "Chart1"Me.Chart1.Size = New System.Drawing.Size(478, 319)

Me.Chart1.TabIndex = 1Me.Chart1.Titles.AddRange(New ChartFX.WinForms.TitleDockable() {TitleDockable1})

Me.Chart1.ToolBar.Visible = True



'Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(507, 363)Me.Controls.Add(Me.Chart1)

Me.Name = "Form1"CType(Me.Chart1, System.ComponentModel.ISupportInitialize).EndInit()


End Sub


End RegionPrivate Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

TryMe.Chart1.Gallery = ChartFX.WinForms.Gallery.Lines

Me.Chart1.Visible = True

Me.Chart1.ToolBar.Visible = TrueMe.Render()

Me.FormatTheChart()Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End SubPrivate Sub Render() Dim aLineX, aLineY As ArrayList

Dim j As Integer


'for test purpose, store X and Y values in two arraylists firstaLineX = New ArrayListaLineY = New ArrayList





For j = 0 To aLineX.Count - 1

If j < aLineX.Count ThenMe.Chart1.Data.X.Item(0, j) = CSng(aLineX.Item(j)) Me.Chart1.Data.Y.Item(0, j) = CSng(aLineY.Item(j))

ElseMe.Chart1.Data.X.Item(0, j) = CSng(aLineX.Item(aLineX.Count - 1)) Me.Chart1.Data.Y.Item(0, j) = CSng(aLineY.Item(aLineY.Count - 1))

End IfNext j


Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End SubPrivate Sub FormatTheChart()

Me.Chart1.AxisX.Grids.Major.Visible = TrueMe.Chart1.AxisX.Grids.Major.Color = Color.FromArgb(128, 128, 0)

Me.Chart1.AxisY.Grids.Major.Visible = TrueMe.Chart1.AxisY.Grids.Major.Color = Color.FromArgb(128, 128, 0)

Me.Chart1.AxisY.DataFormat.Decimals = 4Me.Chart1.AxisY.LogBase = 10 Me.Chart1.AxisY.Min = 0.0

Me.Chart1.AxisY.Max = 0.1 Me.Chart1.AxisY.LabelsFormat.Format = AxisFormat.Scientific

'format series legend

Me.Chart1.Series.Item(0).Text = "test"Me.Chart1.Series.Item(0).MarkerShape = ChartFX.WinForms.MarkerShape.None

Me.Chart1.LegendBox.Visible = TrueMe.Chart1.LegendBox.ContentLayout = ChartFX.WinForms.ContentLayout.Near

Me.Chart1.LegendBox.Dock = ChartFX.WinForms.DockArea.TopEnd Sub


Link to comment
Share on other sites

The problem is this:

Me.Chart1.AxisY.Min = 0

A Log Scale can not represent zero. You must set:

Me.Chart1.AxisY.Min = 0.0001

If you leave the Min at zero, we will recalculated as 10^(-Number of Decimals). Because you have zero decimals (LabelsFormat) this ends up being 1, which inverts the Y-Axis.

Link to comment
Share on other sites

  • 2 months later...
Hi Frank,

I have a similar problem and I'm hoping you could help me out.

In a general solution, sometimes the range of the data is unknown until runtime, therefore Chart.AxisY.Min needs to computed. Although it's a bit inconvenient, but it's not too terrible to get around. However, if LabelsFormat.Format is not set to Scientific (i.e.: Number), then the axis label has a problem displaying ticks that are between 0 and 1. The LabelsFormat.Decimal has to be set in order display these correctly, but that would affect the ticks that are above 1 as well. Here's an example:

With AxisY.Min = 0.0001 and AxisY.Max = 1000, and LabelsFormat.Decimal = 4, the Y-axis labels would be:

0.0001, 0.0010, 0.0100, 0.1000, 1.0000, 10.0000, 100.0000, 1,000.0000

Ideally, the labels should be:

0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1,000

Is there anyway to achieve this?
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...