Displaying 2 straight lines

  • Thread starter Thread starter Gary Thomson
  • Start date Start date
G

Gary Thomson

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.
 
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
 
Back
Top