How to change X axis maximum value

Posted on 2009-04-17
Last Modified: 2013-11-28
per PAQ 20723076, I am trying to change the min and max of a chart's X axis.

If the chart is a scatter chart then this works :
  Me![chartCalibration].Object.Application.Chart.axes(1).maximumscale = 2 ' X axis
  Me![chartCalibration].Object.Application.Chart.axes(2).maximumscale = 2 ' Y axis
but if I change it to a line chart then only the Y axis (2) works, the X axis throws an error.
"unable to set the MaxumumScale property to the Axis class".

The chart is on a form as OLE Microsoft Graph Chart object, not in a subform.

So why can I change the Y axis min-max on either a scatter or line chart but only X min-max on just the scatter, not the line chart?

Me![chartCalibration].Object.Application.Chart.axes(1).maximumscale = 2 ' X axis but only is scatter

  Me![chartCalibration].Object.Application.Chart.axes(2).maximumscale = 2 ' Y axis, works for eith

Open in new window

Question by:LukeB
    LVL 14

    Accepted Solution

    The error you are getting occurs when you have a Category X-axis rather than a Value X-axis.  A line chart has Value-Y and Category-X.  Even if the numbers supplied for X are 1, 9, and 10, they appear evenly spaced on a line graph because they are just 3 category bins. If you look at the X-axis properties window of a line chart, you'll see you have very few options to change on a category axis.

    If you switch the charttype to Scatter, both axes are Value axes and you can set scale, max, min, and the options you are used to.

    You can try the ChartType xlXYScatterLines to get something that looks like the line chart you are used to but has a Value (X) axis.

    If you need to stick to a line chart (because your X data are indeed categorical), you'll need to filter the query that feeds the chart.


    LVL 1

    Author Comment

    Hi PT,
    could you clarify/expand  on "you'll need to filter the query that feeds the chart.
    " ??
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    Can you clarify what you are looking for by posting a sample of your database?

    One trick I use, is to make sure that there is at least one "Dummy" Value that is is just shy of the value that will trigger the Graph to move the Max scale to the next value. (For example: 1.9)

    Are you trying to "Toggle" between a scatter chart and a Line chart with this code?
    Why not just make two charts?

    Again, please clarify with a sample db.


    LVL 14

    Assisted Solution


    I can't guess the type of query you are using as a datasource for the chart. If you can post the SQL and some sample data, that would be great.

    If the source is a crosstab query, you can limit the columns by specifying the the Columns property in the Query Properties, such as: 0;1;2
    This will output exactly these three columns, whether they have data or not.  It's a way to specify a minimum scale and maximum scale for categorical data.

    If the source is a select query (or totals query), and you want to limit the range of the data, add a criterion for the x-axis field, such as
    Between 0 and 2

    All of the above is assuming that you have categorical x-axis data.  If not, or your code is dynamic:

    With Me![chartCalibration].Object.Application.Chart
         .Axes(2).MaximumScale = 2 ' adjust Y axis
         If Axes(1).Type = xlValue Then  'xlValue = 2
              'go ahead and set min, max, auto, majorunit, etc.
             .Axes(1).MaximumScale = 2
              'this axis is categorical and you can't set maximumscale

        End If
    End With



    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now