+ Reply to Thread
Results 1 to 4 of 4

Possible to automatically have "tighter" X and Y-axis bounds in a simple line chart?

  1. #1
    Registered User
    Join Date
    03-01-2020
    Location
    Boston, MA
    MS-Off Ver
    2016
    Posts
    2

    Possible to automatically have "tighter" X and Y-axis bounds in a simple line chart?

    I frequently create a line chart where the X-axis is date/time (just showing time) and the Y axis is a number. Whenever Excel generates the chart, it leaves a fair amount of space on the left and right sides of the chart, before the earliest time/date and after the latest time/date, where there is no data. I'd like the chart to be "tighter," so that the leftmost data point is very close to the Y axis on the left side, and likewise the rightmost data point is very close to the Y axis on the right side. For a time/date X axis, this is particularly cumbersome to implement, because Excel shows those bounds as long, floating point numbers, rather than actual dates and times. I end up having to use trial and error every time to pull in the left and right sides of the chart, increasing the minimum and decreasing the maximum by .001 until it looks right. Is there an easier or, ideally, automated, way to accomplish this?

    I have a similar goal for the Y axis, although this is easier to do manually, since the Y axis is charting numbers, so I can just manually enter in the lowest and highest number to bring the chart in that way.

    I'd be open to a VBA recipe if that's the only way as well.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,444

    Re: Possible to automatically have "tighter" X and Y-axis bounds in a simple line chart?

    Administrative note

    Welcome to the forum

    in your haste to solve your problem, you probably missed the yellow banner advising how to get answers faster by posting a sheet ?

    Please take a moment to read it and attach a sheet accordingly.

    Thanks you for helping us help you

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,429

    Re: Possible to automatically have "tighter" X and Y-axis bounds in a simple line chart?

    You should be able to enter date in the Min/Max scale properties
    If you change the number format from date to General you should see the numeric value of the date.

    You only have the options of auto or fixed value, when it comes to scales. Alas you can not link the scale value directly to a cell.
    Although you can read the values from the cells and set the scale.
    https://peltiertech.com/link-excel-c...lues-in-cells/
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    03-01-2020
    Location
    Boston, MA
    MS-Off Ver
    2016
    Posts
    2

    Re: Possible to automatically have "tighter" X and Y-axis bounds in a simple line chart?

    Thanks, your linked script worked for me. Here's what I ended up with, which is idiosyncratic to my application but perhaps useful as an example for others:

    Please Login or Register  to view this content.
    What this does:
    • Selects the active worksheet
    • Selects the first chart on the active worksheet
    • Selects the data source for the chart, starting on row 48, continuing until the last row that has data, using columns A-C
    • Moves the chart to the top left position on the active worksheet
    • Sets the X-axis range on the chart to match the range of values in column A (row 48 through the last row)
    • Sets the Y-axis range on the chart to match the range of values in column B (row 48 through the last row)
    • Rounds the Y-axis values down by 5 for the minimum and up by 5 for the maximum
    • Sets the worksheet zoom level to 86

    Then I added a hotkey and a quick access icon to invoke this macro.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating a "difficult" or "simple" bar chart
    By NLatuny in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 03-24-2016, 01:20 PM
  2. Update all chart x axis in workbook according to a specific "master chart" VBA query
    By synchrotron in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2015, 06:00 AM
  3. Replies: 0
    Last Post: 01-29-2014, 08:10 PM
  4. [SOLVED] Problem creating Line Chart from columns "date" and "money"
    By brosef in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 11-05-2012, 09:01 AM
  5. Replies: 0
    Last Post: 07-08-2011, 02:25 PM
  6. Replies: 4
    Last Post: 02-03-2008, 05:11 PM
  7. STACKED "bar-line" chart using two axis?
    By FreeBird in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 01-09-2007, 07:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1