Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Charting / February 2004

Tip: Looking for answers? Try searching our database.

Displaying 2 straight lines

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary Thomson - 27 Feb 2004 14:36 GMT
Hi,

Hope someone can tell me how to do this....

I have one set of points which form a straight line -
these are (3.1,0), (3.1,100), (3.1,200), (3.1,300) i.e. a
vertical line.

I have another set of points that form a straight line -
these are (0,0), (3.1,100), (6.2,200), (9.3,300).

I have two problems displaying these:

(1) I want both lines to appear on the same graph;

(2) I want the traingle formed by the points (3.1,100),
(3.1,300) and (9.3,300) to be shaded, as this indicates a
surplus (for the purposes of illustration).

I would imagine there would definitely be a way to display
both straight lines on the one graph, but what about the
2nd probelm I have?

Many Thanks,

Gary.
Jon Peltier - 27 Feb 2004 17:57 GMT
Gary -

Here's your data sheet

 X1   Y1      X2   Y2      X3   Y3
3.1    0       0    0     3.1  300
3.1  300     9.3  300     3.1  100
                          9.3  300

X1-Y1 are for the vertical line, X2-Y2 are for the diagonal line, and
X3-Y3 are to draw a triangle.

Select the cells containing the data and labels for X1 and Y1, and use
the chart wizard to create an XY Scatter chart (NOT a Line chart). Right
click on your new chart, select Source Data, Series Tab, click on the
Add button, and use the mouse to select the X range for X2 and the Y
range for Y2. Click Add again to add X3 and Y3.

The following macro will draw a shape based on the points in series 3:

Sub DrawAShape()
     Dim myCht As Chart
     Dim mySrs As Series
     Dim Npts As Integer, Ipts As Integer
     Dim myShape As Shape
     Dim Xnode As Double, Ynode As Double
     Dim Xmin As Double, Xmax As Double
     Dim Ymin As Double, Ymax As Double
     Dim Xleft As Double, Ytop As Double
     Dim Xwidth As Double, Yheight As Double

     Set myCht = ActiveChart
     Xleft = myCht.PlotArea.InsideLeft
     Xwidth = myCht.PlotArea.InsideWidth
     Ytop = myCht.PlotArea.InsideTop
     Yheight = myCht.PlotArea.InsideHeight
     Xmin = myCht.Axes(1).MinimumScale
     Xmax = myCht.Axes(1).MaximumScale
     Ymin = myCht.Axes(2).MinimumScale
     Ymax = myCht.Axes(2).MaximumScale

     Set mySrs = myCht.SeriesCollection(3)
     Npts = mySrs.Points.Count

     Xnode = Xleft + (mySrs.XValues(Npts) - Xmin) _
         * Xwidth / (Xmax - Xmin)
     Ynode = Ytop + (Ymax - mySrs.Values(Npts)) _
         * Yheight / (Ymax - Ymin)

     With myCht.Shapes.BuildFreeform(msoEditingAuto, Xnode, Ynode)
         For Ipts = 1 To Npts
             Xnode = Xleft + (mySrs.XValues(Ipts) - Xmin) _
                 * Xwidth / (Xmax - Xmin)
             Ynode = Ytop + (Ymax - mySrs.Values(Ipts)) _
                 * Yheight / (Ymax - Ymin)
             .AddNodes msoSegmentLine, msoEditingAuto, Xnode, Ynode
         Next
         Set myShape = .ConvertToShape
     End With

     With myShape
         .Fill.ForeColor.SchemeColor = 13 ' YELLOW
         .Line.ForeColor.SchemeColor = 12 ' BLUE
     End With
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
http://PeltierTech.com/Excel/Charts/
_______

> Hi,
>
[quoted text clipped - 22 lines]
>
> Gary.
Andy Pope - 28 Feb 2004 14:16 GMT
Hi Gary,

I have posted a alternative non vba approach for obtaining the fill area.
(http://www.andypope.info/ngs/ng27.htm)

Cheers
Andy

> Hi,
>
[quoted text clipped - 22 lines]
>
> Gary.

Signature

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.