+ Reply to Thread
Results 1 to 34 of 34

Draw lines in a chart

  1. #1
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116

    Draw lines in a chart

    I would like to connect two data markers with a line to form a rectangular box. Can this be done? Can this process be automated using Macros? Thanks.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You could use formulas (or VBA) to create the five pairs of points for an additional series that forms a box.

  3. #3
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116

    Draw lines in a chart

    Hi SHG - Thank you for your response.

    I also recorded a macro by invoking Picture|AutoShapes from the menu and then drew the lines to form a rectangular box. However, the Macro does not adapt to newer data markers after user data has been changed. I would like the rectangular box to be drawn properly even when the data changes.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You could use formulas (or VBA) to create the five pairs of points for an additional series that forms a box. That calculation would include the appropriate dependency on the data:

    x1 y1
    x2 y1
    x2 y2
    x1 y2
    x1 y1
    Last edited by shg; 07-02-2008 at 06:52 PM.

  5. #5
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Thanks again SHG. I don't understand what the x1 y1 etc. is. But here is what I am facing.

    1. The graph produces a trend line
    2. There are two sets of data marker of which one reflects new data
    3. Starting at the lower most marker, a line needs to be drawn to the left, to the point where this line intercepts the trend line
    4. Starting at the upper data marker, a line is to be drawn to the left
    5. Then the rectangle is completed by drawing vertical lines.

    This process has to be repeated for as many sets of markers that are available on the chart. I hope this is not too very confusing. Thanks.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Each data marker has an associated pair of coordinates (x, y), right? If we're talking about two data markers, then we could refer to two points, say (x1, y1) and (x2, y2).

    From those, you can create five points using formulas that reference the components of those two ...

    x1 y1 ' the first point
    x2 y2 ' the second point

    =x1 =y1 ' formulas that refer to the above
    =x2 =y1
    =x2 =y2
    =x1 =y2
    =x1 =y1

    ... and you can plot the new points as a series, which will appear as a rectangle that intersects the two data markers at opposite corners.

  7. #7
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    SHG - thank you for your response. I need a bit more guidance here as I hav e never worked with the material you are suggesting. Thanks.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    perhaps you could post an example of your data and current chart.

    Then we can explain the solution in context to your data.
    Cheers
    Andy
    www.andypope.info

  9. #9
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi Andy. Thank you for your response. Here is what I am attempting to accomplish.

    There are three sets of data:

    1. Policy Line
    2. Minimum
    3. Maximum

    1, Policy Linea. X axis is Point 100 – 1000b. Y axis is Dollar Amount ($0 – $80,000)c. At 100 Points, the trend line starts at $28,107d. At 1000 Points, the trend line ends at $78,070

    2. Minimum
    a. Has 4 levels
    b. At 200 Points the Minimum is $23,000; at 400 Points, Minimum is
    $33,000; at 650 Points, Minimum is $48,000; at 1000 Points,
    Minimum is $61,000

    4. Maximum
    a. Has 4 levels too
    b. Maximum for each of the Points identified in (2) above are, $33,000,
    $50,000, $60,000, and $80,000 respectively.

    Objective now is to:

    1. Start at the lower left side and draw left from the first minimum point until you reach a point where you would intersect a vertical line coming up from the 100 point mark.

    2. Start at the lower left side and draw left from the first maximum point until you reach a point where you would intersect a vertical line coming up from the 100 point mark.

    3. The draw vertical lines to connect the two horizontal lines.

    4. Repeat this process for each level (in this case 4, but could be more).

    Thanks again.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    It really would be easier if you posted a workbook. And perhaps include boxes you've drawn yourself to illustrate what you want.

  11. #11
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi SHG:

    Here is the worksheet. I have currently drawn the lines in manually using Autoshapes. Thanks.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi SHG:

    The lines in the worksheet that has been posted here should start at each of the data markers (Blue and Pink)to form rectangles for each of the four levels, contrary to how it is displayed in the uploaded worksheet. Thanks.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    The workbook you posted does not have the data that's plotted -- it's linked to some external file. Please try again.

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    It's not 100% clear from your example whether the lines should connect to the points or the trend line.

    This example uses custom error bars.

    It will need value adjustment if the boxes need to be more related to the trend line.

    The other approach is to use an additional xy series where you calculate all the corners, as shg was trying to explain.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi Andy:

    Thank you for your kind response.

    The line should connect the minimum and maximum points vertically and move left to the respective minimum point value, thereby forming a rectangle. This process should repeat for each pay grade. Thanks.

  16. #16
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi SHG:

    Here is the worksheet again. Thanks.
    Attached Files Attached Files

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    As near as I can figure out what you're trying to do, please find attached.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi SHG:

    Thank you for your kind response. Your approach works well for me. I now have macros doing the boxes.

    Andy - thank you for your assistance too.

  19. #19
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    SHG:

    Is there a way of suppressing the word "Series 4" etc from being displayed on the chart? Thanks.

  20. #20
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    As far as I know, if you show a legend, all series will have a name. You could delete the legend add add your own as a text box.

  21. #21
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    Instructions on removing legend entry.
    http://www.andypope.info/charts/deletelegendentry.htm

  22. #22
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Instructions on removing legend entry.
    My Excel lesson for the day, thanks.

  23. #23
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    SHG and Andy:

    Thanks much. As iI experimented with deleting the legend, I accidentally clicked the entire legend box and deleted it. and noticed that running the code again did not re-create the legend part of the chart at all. Is this typical? Thanks.

  24. #24
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    We haven't see your code.

    To restore the legend, select the chart, and do Chart > Chart Options, Legend, ...

  25. #25
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    The chart in question is populated each time a command button on the worksheet is clicked. However, each time the button is clicked, a new set of series to draw the rectangles appears in the legend on the chart.

    How can I avoid this? Thanks.

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

    When you create the chart with code you need to apply the legend with a full set of legend entries.
    Then working backwards remove the legend entries that are not required.

  27. #27
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi Andy:

    Thank you for your response.

    I have recorded macros that plot the four points and produces the rectangle. These in turn add a new set of series each time the macro is run.

    One option is that I can record another macro that removes the word "series" from the legend where applicable. The problem is that, if I record a macro to remove say the four "series" that are currently on the chart -the macro will in the future remove only four. What happens if there are more than four.

    More specifically, when the source data is invoked on the chart, there is both an Add and Remove button. How would I approach remove the unwanted one right there using VBA code? Thanks.

  28. #28
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    well what code have you got for creating the chart?

  29. #29
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi Andy:

    Thank you for your response.

    Here is the code that creates the first rectangle.

    Please Login or Register  to view this content.
    This process is repeated for as many pay grade leves there may be. Thanks.
    Last edited by VBA Noob; 07-08-2008 at 02:49 PM.

  30. #30
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    A workbook would have been much simpler.

    The code will delete the last item in the legend.

    Please Login or Register  to view this content.
    Please remeber to use code tags when posting code.

  31. #31
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi Andy:

    What are code tags? Thanks.

  32. #32
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    Code Tags: Make your code easier for us to read
    http://www.excelforum.com/misc.php?do=bbcode#code

  33. #33
    Forum Contributor
    Join Date
    06-23-2008
    Posts
    116
    Hi Andy:

    Where in the code posted should the code you provided go. I am not sure where to place this code. Thanks.

  34. #34
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    Inside the routine you currently have for creating the chart. After code that adds all the series.
    The removal of legend entries should be the last thing your routine does to the chart as the only way to deal with legend entries is with the index number and that does not always tally with the series dur to the way the legend is ordered.
    You can not easily associate a legend entry with a series.

+ 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