• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 911
  • Last Modified:

How to change X axis maximum value

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

0
LukeB
Asked:
LukeB
  • 2
2 Solutions
 
pteranodon72Commented:
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.

HTH,

pT
0
 
LukeBAuthor Commented:
Hi PT,
could you clarify/expand  on "you'll need to filter the query that feeds the chart.
" ??
0
 
Jeffrey CoachmanCommented:
LukeB,

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.

Thanks

JeffCoachman
0
 
pteranodon72Commented:
LukeB,

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
     Else
          'this axis is categorical and you can't set maximumscale

    End If
End With


HTH,

pT
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now