eric Posted June 13, 2007 Report Share Posted June 13, 2007 I provide only two points (0.01, 0.0007) and (1000000, 0.0007) to make a line. The code is simple: Me .Chart1.Data.X.Item(0, 0) = 0.01Me.Chart1.Data.X.Item(0, 1) = 1000000 Me.Chart1.Data.Y.Item(0, 0) = 0.0007Me.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.0008Then 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 More sharing options...
Frank Posted June 14, 2007 Report Share Posted June 14, 2007 When using Log Scale, labels are displayed at the powers of 10. You need to set: Me.Chart1.AxisY.LabelsFormat.Decimals = 4 Me.Chart1.AxisY.Min = 0.0Me.Chart1.AxisY.Max = 0.1 Link to comment Share on other sites More sharing options...
eric Posted June 14, 2007 Author Report Share Posted June 14, 2007 Thanks Frank. You are right, the Y label does show up now, but I can't see the plotted line anymore, any idea? thanks Link to comment Share on other sites More sharing options...
Frank Posted June 23, 2007 Report Share Posted June 23, 2007 Please post a complete sample. This code produces the desired chart on my end. Link to comment Share on other sites More sharing options...
eric Posted July 10, 2007 Author Report Share Posted July 10, 2007 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: Imports ChartFX.WinFormsPublic Class Form1 # Region " Windows Form Designer generated code "Public Sub New()MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() '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. InitializeComponent() '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 components.Dispose() 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 <System.Diagnostics.DebuggerStepThrough()> 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() ' 'Chart1 '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 ' 'Form1 '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() Me.ResumeLayout(False)Me.PerformLayout() 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 TryMe.Chart1.Data.Clear() 'for test purpose, store X and Y values in two arraylists firstaLineX = New ArrayListaLineY = New ArrayList aLineX.Add(0.01) aLineX.Add(1000000) aLineY.Add(0.0007) aLineY.Add(0.0007) 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 End Class Link to comment Share on other sites More sharing options...
Frank Posted July 13, 2007 Report Share Posted July 13, 2007 The problem is this: Me.Chart1.AxisY.Min = 0 A Log Scale can not represent zero. You must set: Me.Chart1.AxisY.Min = 0.0001If 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 More sharing options...
Weslie Leung Posted October 11, 2007 Report Share Posted October 11, 2007 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 More sharing options...
Frank Posted October 12, 2007 Report Share Posted October 12, 2007 I think this is what you are looking for: chart1.AxisY.LogBase = 10; chart1.AxisY.LabelsFormat.Decimals = 4; chart1.AxisY.LabelsFormat.CustomFormat = "g4"; // General numeric format Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.