MSChart and Auto X axis
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: MSChart and Auto X axis

  1. #1
    Join Date
    Jul 2007
    Posts
    20

    MSChart and Auto X axis

    Hi, in runtime I can see that X-axis limits of my chart (minimum and maximum) are automatically changed as I insert points. That's nice. So I came to an idea to change that minimum and maximum values. It worked. But as soon as I wanted to return (at runtime) to auto I came across some problems. First I discovered that when auto scaling is activated this values are:

    Code:
    myChart.ChartAreas(0).AxisX.Maximum = Double.NegativeInfinity
    myChart.ChartAreas(0).AxisX.Minimum = Double.NegativeInfinity
    So I then (at runtime) returned this values to Double.NegativeInfinity hoping that Chart will then automatically (again) scale X axis. Instead I got exception:

    Code:
    Axis Object - The minimum value of the axis is greater than the largest data point value.
    Stack:

    Code:
       at System.Windows.Forms.DataVisualization.Charting.Axis.EstimateAxis(Double& minimumValue, Double& maximumValue, Boolean autoMaximum, Boolean autoMinimum)
       at System.Windows.Forms.DataVisualization.Charting.Axis.EstimateAxis()
       at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetDefaultFromIndexesOrData(Axis axis, AxisType axisType)
       at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetDefaultAxesValues()
       at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetData(Boolean initializeAxes, Boolean checkIndexedAligned)
       at System.Windows.Forms.DataVisualization.Charting.ChartArea.ReCalcInternal()
       at System.Windows.Forms.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly)
       at System.Windows.Forms.DataVisualization.Charting.Chart.OnPaint(PaintEventArgs e)
       at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
       at System.Windows.Forms.Control.WmPaint(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at SemaDataAcquisition.My.MyApplication.Main(String[] Args) in xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxcxxxx.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
    As you can see from Call stack, exception did not originated from my code, but was definitely caused by this code:

    Code:
    myChart.ChartAreas(0).AxisX.Maximum = 150
    myChart.ChartAreas(0).AxisX.Minimum = 50
    myChart.ChartAreas(0).AxisX.Maximum = Double.NegativeInfinity
    myChart.ChartAreas(0).AxisX.Minimum = Double.NegativeInfinity
    Note that default values ARE Double.NegativeInfinity!

    Any help is greatly appreciated.
    Last edited by Vila; April 29th, 2010 at 02:47 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,877

    Re: MSChart and Auto X axis

    Shouldn't the MAX be POSITIVE?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2011
    Posts
    1

    Re: MSChart and Auto X axis

    Use Double.NaN to set the Minimum or Maximum back to "auto" mode.

    Axis a = chartTheta.ChartAreas[0].AxisX;
    a.Maximum = Double.NaN;

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center