+ Reply to Thread
Results 1 to 2 of 2

x-axis showing the 1. of the month

  1. #1
    Registered User
    Join Date
    04-03-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    27

    x-axis showing the 1. of the month

    Hi people

    I have been dealing with a problem for a loong time. It is about a graphs x-axis for stock closing prices. The data consists only of dates (col A) and a prices (col B). Need help with graph x-axis.xlsm

    Sometimes there are no data for the 1st in the month. Sometimes there is. Also each data set for each month does not consist of the same number of days. E.g. one month can have 20 dates and prices another can have 18.

    The space between the ticks (i think they are called) should therefore vary!

    I would love an x-axis that shows the first day of the month (where data exits) for maybe each (each second/third) month.


    Sub Chart()
    Dim sht As Worksheet
    Dim cht As Object
    Dim chtrng As Range
    Dim chtrngX, chtrngY As Range
    Dim chttitle As String

    Set sht = ThisWorkbook.Worksheets("Share Price")
    Set chtrng = sht.Range(sht.Cells(Rows.Count, 1).End(xlUp), _
    sht.Cells(1, Columns.Count).End(xlToLeft))
    Set chtrngX = chtrng.Columns(1).Offset(1).Resize(chtrng.Rows.Count - 1)
    Set cht = sht.ChartObjects.Add(Left:=35, Top:=45, Width:=400, Height:=150)

    With cht.Chart
    chttitle = "Stock"
    .Parent.Name = chttitle
    .ChartType = xlXYScatterLinesNoMarkers '#
    .PlotVisibleOnly = False
    .HasLegend = False

    '##################################################
    With .Axes(xlCategory, xlPrimary) ' x-axis
    Dim xMin, xMax As Single
    .HasTitle = False
    '?
    '.CategoryType = xlTimeScale
    '.MajorUnitScale = xlMonths
    ‘?
    ‘Make sure x-axis starts at 1st in the month
    xMin = DateSerial(Year(Application.WorksheetFunction.Min(chtrngX)), Month(Application.WorksheetFunction.Min(chtrngX)), 1)
    xMax = DateSerial(Year(Application.WorksheetFunction.Max(chtrngX)), Month(Application.WorksheetFunction.Max(chtrngX)) + 1, 0) + 1
    .MinimumScale = xMin
    .MaximumScale = xMax
    .TickLabels.NumberFormat = "dd-mmm-yy"
    End With
    '##################################################


    With .Axes(xlValue, xlPrimary) 'y-axis
    .HasTitle = False
    End With

    .Axes(xlCategory).TickLabels.Font.Size = 6
    .Axes(xlValue).TickLabels.Font.Size = 6

    Dim jSeries As Byte
    For jSeries = 2 To chtrng.Columns.Count 'add variable no. of series from columns
    With .SeriesCollection.NewSeries
    .Values = chtrngX.Offset(, jSeries - 1)
    .XValues = chtrngX
    .Name = chtrng(1, jSeries)
    .Format.Line.Weight = 0.8
    .Border.Color = 131
    End With
    Next

    With .ChartTitle
    .Font.Size = 8
    .Top = -1
    .Text = chttitle
    End With

    With .PlotArea
    .Top = 15
    .Left = 12
    .Height = 115
    .Width = 500
    End With
    End With
    End Sub



    Would be so nice to have a good looking graph.!

    Thanks in advance for all your replies!

    /Damp

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: x-axis showing the 1. of the month

    This forum can be quite strict about enclosing code in code tags (see FAQ if you need help with this forum feature). Please do so to avoid getting your topic locked.

    I would suggest these two tutorials that discuss the different type of x axes that Excel uses. In particular, note the difference between a "line chart with a date axis" and an "XY scatter chart with a numeric axis".

    http://peltiertech.com/Excel/ChartsH...ValueAxis.html
    http://peltiertech.com/line-charts-vs-xy-charts/

    In this case, I think you will have more success getting what you want if you will use a line chart with a date axis. With this chart type, you should be able to get the effect you want by changing the max, min, major, and/or minor units of the axis.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. Data Validation Lists & showing Month over Month performance
    By hilpup24 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-22-2012, 11:32 AM
  2. Replies: 0
    Last Post: 07-08-2011, 02:25 PM
  3. Replies: 5
    Last Post: 01-09-2009, 10:11 AM
  4. X-axis not showing all values
    By jcherian in forum Excel General
    Replies: 2
    Last Post: 01-22-2008, 03:12 PM
  5. Chart w/x axis showing different series
    By JIBG in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-23-2007, 09:12 PM
  6. Showing a break in the Y axis
    By Craig in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-26-2006, 09:30 PM
  7. [SOLVED] showing all values on the Y axis
    By dshemesh in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-06-2005, 10:05 AM
  8. Chart Y axis dollars, X axis month-year
    By vandelln in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-17-2005, 05:24 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