+ Reply to Thread
Results 1 to 10 of 10

Area chart "base" seems to rise

Hybrid View

  1. #1
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Area chart "base" seems to rise

    Hi, I'm having more charting issues.

    I plot a chart and make it an area chart. So far so good. When I move that chart to a different sheet, suddenly the base seems to rise. It starts at 0 where it should be, but then increases to almost 0.8. Does anyone know why this might be happening?

    The workbook I have has a ton of personal data, so I'm going to post a screenshot. I realize this is generally frowned upon, but it shows the problem sufficiently.
    Attached Images Attached Images
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,320

    Re: Area chart "base" seems to rise

    Without being able to see the chart and its source data, I suspect it will be hard to say.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Area chart "base" seems to rise

    Yeah, I kind of figured that. Anyway, I figured out how to fix it, but I still don't understand what is going on behind the scenes to cause it. When I set the hidden and empty cells to Gaps, it changes the graph back to how I would expect it to look. If I leave it on Zero, it stays as it looks above in the screenshot.
    If anyone can explain why this happens, I'd certainly apppreciate it.

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

    Re: Area chart "base" seems to rise

    Can you post example of data and chart
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Area chart "base" seems to rise

    A bit delayed, but here is the example:
    Attached Files Attached Files

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

    Re: Area chart "base" seems to rise

    The chart object is corrupt for some reason.
    Simply delete it and add a new chart, remember to fix the value axis to start at zero.

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Area chart "base" seems to rise

    I tried deleting the graph and adding a new one, but the new one is exhibiting the same behavior. I am manipulating the graph by code, shown below. Don't be put off by the length, it is well commented.


    Public Sub UpdateDifferencesGraphData(strInv1 As String, strInv2 As String, strInv3 As String, strAmort As String, _
        strNR1 As String, strNR2 As String, strNR3 As String)
        'The purpose of this procedure is to clear out the existing graph data from the Differences Graph Data sheet and then
        'transfer the imported pricing data into the Differences Graph Data sheet, and lastly fill the labels for the graph
        'which lie on the Differences Graph Data sheet.
        
        'Declare local variables.
        Dim i As Integer
        
        'Initialize Variables.
        i = 3
        
        'Working with the Difference Graph Data sheet.
        With Sheets("Differences Graph Data")
            'Activate the sheet.
            .Activate
            'Clear the existing graph data.
            .Range(Cells(3, 1), Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 7)).ClearContents
            'Put the Date header in.
            .Cells(2, 1).Value = "Date"
        End With
        
        'Working with the table sheet that was imported from Access.
        With Sheets("tbl_Graph_Data_Differences")
            'Copy the used range, minus the header.
            .UsedRange.Offset(1, 0).Copy Destination:=Sheets("Differences Graph Data").Cells(3, 1)
            'Turn off alerts so the user isn't warned about deleting the sheet.
            Application.DisplayAlerts = False
            'Delete the sheet because we are finished with it.
            .Delete
            'Turn alerts back on.
            Application.DisplayAlerts = True
        End With
        
        
        
        'Working with the Difference Graph sheet again.
        With Sheets("Differences Graph Data")
            'Clear all rows that have no data except the date.
            Do Until i >= .Cells(Rows.Count, 1).End(xlUp).Row + 1
                'If the sum of the row is equal to the date value, then it has no other data in it.
                If WorksheetFunction.Sum(.Rows(i)) = .Cells(i, 1).Value Then
                    'Delete the row.
                    .Rows(i).Delete
                    'We need to check the next row which just moved up.
                    i = i - 1
                End If
                i = i + 1
            Loop
            'Put the Amortization as the header.
            .Cells(1, 1).Value = strAmort & " Price Differences"
            'If Investor 2 and Note Rate 1 exist.
            If strInv2 <> "" And strNR1 <> "0.000" Then
                'Put the Investor and note rate into the header for this column of data.
                .Cells(2, 2).Value = "Generic / " & strInv2 & " " & strNR1 & "% Difference"
                'Make sure the column is not hidden.
                .Columns(2).Hidden = False
            Else
                'If the note rate has not been populated, hide the column.
                .Columns(2).Hidden = True
            End If
            'If Investor 2 and Note Rate 2 exist.
            If strInv2 <> "" And strNR2 <> "0.000" Then
                'Put the Investor and note rate into the header for this column of data.
                .Cells(2, 3).Value = "Generic / " & strInv2 & " " & strNR2 & "% Difference"
                'Make sure the column is not hidden.
                .Columns(3).Hidden = False
            Else
                'If the note rate has not been populated, hide the column.
                .Columns(3).Hidden = True
            End If
            'If Investor 2 and Note Rate 3 exist.
            If strInv2 <> "" And strNR3 <> "0.000" Then
                'Put the Investor and note rate into the header for this column of data.
                .Cells(2, 4).Value = "Generic / " & strInv2 & " " & strNR3 & "% Difference"
                'Make sure the column is not hidden.
                .Columns(4).Hidden = False
            Else
                'If the note rate has not been populated, hide the column.
                .Columns(4).Hidden = True
            End If
            'If Investor 3 and Note Rate 1 exist.
            If strInv3 <> "" And strNR1 <> "0.000" Then
                'Put the Investor and note rate into the header for this column of data.
                .Cells(2, 5).Value = "Generic / " & strInv3 & " " & strNR1 & "% Difference"
                'Make sure the column is not hidden.
                .Columns(5).Hidden = False
            Else
                'If the note rate has not been populated, hide the column.
                .Columns(5).Hidden = True
            End If
            'If Investor 3 and Note Rate 2 exist.
            If strInv3 <> "" And strNR2 <> "0.000" Then
                'Put the Investor and note rate into the header for this column of data.
                .Cells(2, 6).Value = "Generic / " & strInv3 & " " & strNR2 & "% Difference"
                'Make sure the column is not hidden.
                .Columns(6).Hidden = False
            Else
                'If the note rate has not been populated, hide the column.
                .Columns(6).Hidden = True
            End If
            'If Investor 3 and Note Rate 3 exist.
            If strInv3 <> "" And strNR3 <> "0.000" Then
                'Put the Investor and note rate into the header for this column of data.
                .Cells(2, 7).Value = "Generic / " & strInv3 & " " & strNR3 & "% Difference"
                'Make sure the column is not hidden.
                .Columns(7).Hidden = False
            Else
                'If the note rate has not been populated, hide the column.
                .Columns(7).Hidden = True
            End If
        End With
    
    End Sub
    Explanation of code:
    Clear off previous graph data. Paste new graph data from results that have been exported onto a sheet from Access. Delete that sheet from Access. If any rows have no data, delete them. Set the graph header, gotten from cell 1,1 of the table. Check each column for data. If none is present, hide the column so it will not be graphed. The reason for this is the user is given an option to show up to 6 sets of data on the graph, and if they choose to do less than 6 but the columns are not hidden, the series markers will show up in the legend.

    Thanks Andy
    Last edited by davegugg; 05-24-2011 at 11:20 AM.

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

    Re: Area chart "base" seems to rise

    None of that code creates a chart.

    I can not test it as I do not know what the arguments are.

    The following, for me, creates a valid area chart on the Charts tab.

    Sub x()
    
        Dim objCht As ChartObject
        Dim chtTemp As Chart
        Dim rngData As Range
        Dim rngLabels As Range
        Dim strName As String
        
        Set rngLabels = Worksheets("Differences Graph Data").Range("A3:A4929")
        Set rngData = rngLabels.Offset(0, 1)
        strName = rngData.Cells(1, 1).Offset(-1, 0)
        
        Set objCht = rngData.Parent.ChartObjects.Add(1, 10, 200, 150)
        objCht.Chart.Location xlLocationAsObject, "Charts"
        Set chtTemp = ActiveSheet.ChartObjects(ActiveSheet.ChartObjects.Count).Chart
        
        With chtTemp.Parent
            .Left = 1
            .Top = Charts("Charts").ChartArea.Height / 2
            .Width = Charts("Charts").ChartArea.Width
            .Height = .Top
        End With
        
        With chtTemp
            With .SeriesCollection.NewSeries
                .Name = strName
                .Values = rngData
                .XValues = rngLabels
            End With
            .ChartType = xlArea
            .HasTitle = True
            .ChartTitle.Text = "Price Difference"
        End With
        
        
    End Sub

  9. #9
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Area chart "base" seems to rise

    No, I'm not creating a chart. I have a chart set up and defined, and my code just changes the data that the chart will display. The arguments come in as the titles of the data charted - unless the user has not chosen to chart all 6 sets of data. In my posted example, strInv1 would have been "FAMC", strNR1 would have been "4.750%", strInv2 and strInv3 = "" and strNR2 and strNR3 = "0.000%".

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

    Re: Area chart "base" seems to rise

    Here is the workbook with a new chart correctly displayed. If the chart alters after running your code I would check to see the version of excel you have has all the service packs and updates applied.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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