Results 1 to 3 of 3
  1. #1
    alangea is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Posts
    4

    Chart axis change with .Chartype changes

    I have done some coding in VBA to export data from a Query to Excel, have Excel draw a chart and then export it to jpg to import in a report.
    I am facing a problem with my X axis in the chart. It changes when changing the charttype to xlXYScatterLinesNoMarkers

    Here is the code:

    Sub open_excel_file(filename As String)
    Dim MinX As Double
    Dim MaxX As Double
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook


    Dim xlWS As Excel.Worksheet
    Dim SQL As String
    Dim personid As Double
    Dim mindato As Date
    Dim maxdato As Date
    Set xlApp = New Excel.Application


    'Find værdier på akser
    'KG akse
    personid = Me.Id.Value
    SQL = "SELECT Person_kg.Dato, Person_kg.Weight, Person_data.Max_kg, Person_data.Maal FROM Person_data INNER JOIN Person_kg ON Person_data.Id = Person_kg.Person_id WHERE Person_data.Id = " & personid & " ORDER BY Person_kg.Dato DESC"
    MinY = min_in_columns(SQL, 1, 3) - 1
    MaxY = max_in_columns(SQL, 1, 3) + 1
    mindato = min_date_columns(SQL, 0, 0)
    maxdato = max_date_columns(SQL, 0, 0)

    'Max and Min for axis is now calculated
    'Open Excel file
    ' Set xlApp = CreateObject("Excel.Application")
    With xlApp
    .Visible = True
    Set xlWB = .Workbooks.Open(filename, , False)
    End With
    Set xlWS = xlWB.Worksheets("Graph")

    'Format colum A in Excel sheet to dates
    xlWS.Columns("A:A").NumberFormat = "DD-MM-YY"
    xlWB.Charts.Add 'chart is open and shows dates correct
    With xlWB.ActiveChart
    .ChartType = xlXYScatterLinesNoMarkers 'chart changes and shows dates incorrect.
    .HasTitle = False 'True
    ' .ChartTitle.Characters.Text = "Name"
    .Axes(xlCategory).CategoryType = xlDate
    .Axes(xlCategory).BaseUnit = xlDays
    .Axes(xlValue).MinimumScale = MinY
    .Axes(xlCategory).MinimumScale = mindato
    .Axes(xlCategory).MaximumScale = maxdato
    .AutoScaling = True
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dato"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Vægt [Kg]"
    .Axes(xlCategory).HasMajorGridlines = True
    .Axes(xlCategory).HasMinorGridlines = False
    .Axes(xlValue).HasMajorGridlines = True
    .Axes(xlValue).HasMinorGridlines = False

    End With
    filename2 = Replace(filename, ".xls", ".jpg")
    xlWB.ActiveChart.Export filename2, FilterName:="JPG"
    'Closing Excel
    ActiveWorkbook.Saved = True
    xlWB.Close
    xlApp.Quit
    Set xlWB = Nothing
    DoEvents
    Set xlApp = Nothing
    DoEvents
    Dim strClsExl As String
    strClsExl = "TASKKILL /F /IM Excel.exe"
    Shell strClsExl, vbHide


    End Sub


    Here pictures of the charts.

    Correct dates:
    Click image for larger version. 

Name:	Noname.jpg 
Views:	4 
Size:	71.7 KB 
ID:	7725

    After changing the x axis has changes, steps now varies:
    Click image for larger version. 

Name:	Noname2.jpg 
Views:	5 
Size:	25.8 KB 
ID:	7726

    Anybody has a solution to keep the correct format of the date x axis?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Have you considered building the graph in the Access report?

    I analyze graph issues best by reviewing and testing directly if you want to provide file.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    alangea is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Posts
    4
    Hi again.
    I changed the Chartype to xlLine.
    That did the job and now the chart is correct

    Click image for larger version. 

Name:	Noname.jpg 
Views:	3 
Size:	37.8 KB 
ID:	7727

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-29-2012, 04:38 PM
  2. Scatter Chart not Showing X-axis Values
    By ward0749 in forum Forms
    Replies: 4
    Last Post: 03-20-2012, 06:37 AM
  3. Replies: 4
    Last Post: 03-04-2012, 08:59 PM
  4. Perplexing scatter chart x-axis problem
    By whatwouldmattdo in forum Queries
    Replies: 3
    Last Post: 11-28-2011, 09:38 AM
  5. Replies: 2
    Last Post: 07-12-2010, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums