+ Reply to Thread
Results 1 to 16 of 16

Connecting points in a graph

Hybrid View

  1. #1
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Connecting points in a graph

    Hi. I have a data and it has been plotted into a graph. Here's what i have: I have 2 points, point A and point B with caps, 1.00 and 2.00 respectively. So now i need to draw 3 parallel lines, i.e from the caps and the main point itself. How do i do that? Manually will be of course selecting a line from the shapes. Any suggestions? Thanks a lot in advance.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Connecting points in a graph

    hi rshin2020,

    welcome to the forum.

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Include the graph and manually add the lines you require with the drawing tool. This will illustrate what you want to achieve.

    Doing this will ensure you get the result you need!

  3. #3
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Connecting points in a graph

    I've attached the graph in Ms Word. The point is the brown box on your left. -2.00 and 10.00 coordinate. Please help. Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Connecting points in a graph

    uhmm, if you are trying to create the graph in Excel, please attach your Excel file with the source data and the graph. If the file is large, reduce the data to a minimum set that illustrates your issue and/or zip the file.

  5. #5
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Connecting points in a graph

    I'm sorry, the file is still too large. I cant seem to shrink it to send it here. Is there another way? Besides, the information here is private and confidential. I would appreciate it if you could view it in word first.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Connecting points in a graph

    OK, I've had a look at the Word doc. I see two charts with many data points. They look great. A JPG of GIF of the same screenshot would have taken a less lot bandwidth, by the way.

    I don't see any explanation of what you want to achieve and no examples of what you want to do, nor any logic that leads to the results, which aren't illustrated anyway.

    What to do? Create a sample Excel file with just a few data points that follow the same principles as the chart in your Word file. Create the chart that goes with it. Use dummy data. Then upload that file here and explain what you want to do. Use the drawing tool to create lines that you can't create within the chart. Explain the logic that leads to the lines.


  7. #7
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Connecting points in a graph

    Ok, its was a bit difficult as all the value are plotted with calculated values from various sheets. Here's the sample. What i would like to achieve is the one with the blue line. The caps and the point itself has to have a parallel line till it almost reaches the next range. X-axis is the range.
    Attached Files Attached Files

  8. #8
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Connecting points in a graph

    Sorry, I don't seem to succeed in making myself clear.

    You've now uploaded an empty chart and hand drawn a few lines. But there's no reference to the actual data point/series that the lines refer to, nor where they are stored. I'm sure you don't want the lines to be random, but that they should have some kind of connection/relation to existing data. But without that existing data, it's hard to make that connection.

    Your answer probably lies in adding data series to the XY chart, but I can't see how to recommend a solution without the data.

    Can you create a sample file where the chart has some actual data series? If in your original file, the values are from external files, just copy them and use paste special - values to put them into the table that feeds the chart.

  9. #9
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Smile Re: Connecting points in a graph

    Ok. I believe now the graph is complete. I did what u asked. The bold lines (3 lines) are what i am suppose to do. It doesnt have to touch the 2nd point in the next range. It is just to show comparison. Thanks.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Smile Re: Connecting points in a graph

    I practically gave you the information you wanted! I just need to connect the caps of a point to the next point. The lines have to be parallel. why 3 lines? its because the first and the third has to come from the caps of the point A and the second from right in the middle. Its okay if you find it difficult. Sorry for the trouble. I'll just ask somewhere else. Thank you for your time.

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

    Re: Connecting points in a graph

    If by caps you mean error bars then you are using custom values which means you have values within the worksheet.

    You need to use additional xy-scatter data series plotting points calculated via formula based on the xy-point and the error values.

    As your example files only contain links to the original data file on your server we can not provide a more complete answer.
    Cheers
    Andy
    www.andypope.info

  12. #12
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Connecting points in a graph

    I appreciate you understanding my problem. I have found a solution to it but using VB code. I do not understand the code that well. Is it alright to post it here?

  13. #13
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Connecting points in a graph

    I did what u asked.
    No, You did not!

    Sorry. I'm about to give up on this. Although I can now see data points in the chart, I can still not see the underlying values anywhere in the sheet. Also, you have given no explanation as to why the lines are where they are, why they start where they start, why they end where they end, or why they are as long as they are. Or why there are three lines, not 7 or 2.

    Try to put yourself in my shoes. I'm currently just looking at a picture of a chart with a few hand drawn lines. If I am to provide a solution how to create these lines with Excel, you have to give me some information towards how these lines come about and why you want them there.

    ??
    Last edited by teylyn; 01-06-2010 at 02:48 AM.

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

    Re: Connecting points in a graph

    Sure you can post it, remember to use code tags.

  15. #15
    Registered User
    Join Date
    01-05-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Connecting points in a graph

    Thanks. Here's the code:
    Option Explicit
    Private SheetGraph As Worksheet
    Private SheetData As Worksheet
    Private Const FrequencyCount As Integer = 21
    Private ReferenceData As String
    Private Const sUpperLimit As String = "Upper"
    Private Const sLowerLimit As String = "Lower"
    
    Public Sub ChangeChartsParameters()
    
    Set SheetGraph = Sheet2
    Set SheetData = Sheet3
    ReferenceData = "=" & SheetData.Name & "!"
    Chart "110", 334
    'Chart "100", 312
    'Chart "90", 290
    'Chart "80", 268
    'Chart "70*", 246
    'Chart "70", 224
    'Chart "60*", 202
    'Chart "60", 180
    'Chart "50*", 158
    'Chart "50", 136
    'Chart "40*", 114
    'Chart "40", 92
    'Chart "20", 48
    'Chart "110", 334
    
    MsgBox "Done"
    
    End Sub
    
    Private Sub Chart(dB As String, rowStart As Integer)
        
        Dim ChartObject As Object
        
        'Find the value of dB which matches with ChartTitle
        For Each ChartObject In SheetGraph.ChartObjects
            ChartObject.Activate
            If Left(ActiveChart.ChartTitle.Caption, Len(dB)) = dB Then
                Dim Series As Object
                For Each Series In ActiveChart.SeriesCollection   *
                    If Series.Name = sUpperLimit Or Series.Name = sLowerLimit Then  *
                        ChangeSeriesLimit Series, rowStart
                    Else
                       ChangeSeries Series, rowStart
                    End If
                Next
            
            End If
        Next
    
    End Sub
    
    Private Sub ChangeSeries(Series As Object, rowStart As Integer)
        Dim col As Integer, colItem As Integer
        col = FindCaptionAtRow(Series.Name, 1) 'Series.Name must match with the Header
        
        colItem = 0 'Frequency
        Series.XValues = ReferenceData & "R" & rowStart & "C" & col + colItem & ":R" & rowStart + FrequencyCount - 1 & "C" & col + colItem
        colItem = 1 'Attenuation
        Series.Values = ReferenceData & "R" & rowStart & "C" & col + colItem & ":R" &  rowStart + FrequencyCount - 1 & "C" & col + colItem    *
        
        'Change Error Bars
        colItem = 2 'MU for Y Error Bars
        Dim errorRange As String
        errorRange = ReferenceData & "R" & rowStart & "C" & col + colItem & ":R" & rowStart + FrequencyCount - 1 & "C" & col + colItem
        Series.ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlCustom, Amount:=errorRange, MinusValues:=errorRange
    End Sub
    
    Private Sub ChangeSeriesLimit(Series As Object, rowStart As Integer)
        Dim colX As Integer, colLimit
        colX = FindCaptionAtRow("Ref", 1) '"Ref" must match with the Header
        colLimit = FindCaptionAtRow(Series.Name, 2) '"Ref" must match with the Header
    
        Series.XValues = ReferenceData & "R" & rowStart & "C" & colX & ":R" & rowStart + FrequencyCount - 1 & "C" & colX
        Series.Values = ReferenceData & "R" & rowStart & "C" & colLimit & ":R" & rowStart + FrequencyCount - 1 & "C" & colLimit
    
    End Sub
    
    Private Sub ChangeErrorBars(Series As Object, index As Integer)   *The whole section
        
        With Series
            .ErrorBar Direction:=xlX, Include:=xlBoth, _
            Type:=xlCustom, Amount:="=Sheet1!R1C3:R10C3", MinusValues:= _
            "=Sheet1!R1C3:R10C3"
            .ErrorBar Direction:=xlY, Include:=xlBoth, _
            Type:=xlCustom, Amount:="=Sheet1!R1C3:R10C3", MinusValues:= _
            "=Sheet1!R1C3:R10C3"
        End With
    
    End Sub
    
    'Find a string at desired row and return column number
    Private Function FindCaptionAtRow(label As String, row As Integer) As Integer
        Dim i As Integer
        Do
            i = i + 1
            Debug.Print SheetData.Cells(row, i).Value    *
        Loop Until SheetData.Cells(row, i).Value = label Or i = 100
        If i = 100 Then
            Err.Raise 1001, "FindCaptionAtRow", "Can't find match"
        Else
            FindCaptionAtRow = i
        End If
    End Function
    The * indicates the ones i need explanation. Thanks a lot.

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

    Re: Connecting points in a graph

    * loops through each series in the chart
    * checks name of series
    * sets the range to use for values using R1C1 notation
    * prints contents of cells to immediate window in VBE ( CTRL+G to display immediate window)

+ 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