| Contents > Tutorials > Chart Tutorials | Index |
Vector Fields and Directed Graphs
This style of plot can be used in two very different ways, to show either directed graphs, or to plot vector fields as a scatter diagram. The examples illustrate both of these.
Plotting a Vector Field
This style of chart is common in oceanography or weather-forecasting. The first (xy) pair is used to plot the location of the reading, and the offset to the second pair represents the direction and value of some measured quantity like windspeed or current flow.

int[,] vectorfield = new int[,] {{77,17,93,24},{25,48,31,57},{43,55,51,65},{42,24,50,31},{93,52,114,63},
{32,74,40,85},{81,31,99,41},{14,98,19,110},{64,70,78,83},{4,63,7,75},{71,63,86,75},{98,43,121,53},
{22,7,28,12},{51,33,62,42},{89,72,108,84},{53,55,65,67},{24,81,30,93},{22,91,28,103},{55,83,67,97},
{45,82,56,96},{48,65,58,78},{50,62,62,74},{59,89,72,101}};
sp.Reset(width,height);
sp.Heading = "Map of Current Flow";
sp.VectorStyle = VectorStyles.ArrowLines;
sp.DrawVectors(vectorfield);
Typically the lines have arrowheads to indicate the flow direction. This chart can also be used for any kind of vector field, for example to show the slope at any point on a landscape.
Labelling the Vectors
This example adds value-tags to each vector (giving the length of the line) and shows the root of each line as well as the length and direction.

sp.Heading = "Wind Direction and strength"; sp.VectorStyle = VectorStyles.Rooted|VectorStyles.ValueTags|VectorStyles.ArrowLines; sp.ValueTagFormat = "##0"; sp.SetMarkers(Marker.Bullet); sp.DrawVectors(vectorfield);
In most cases, you would set your own value data here as the scaling of the lines is generally quite arbitrary.
Simple Connected Graph
This chart can easily be used to draw simple diagrams, typically representing connected tasks, such as an assembly process.

// Connections as 4 arrays
x1 = new int[] {1,1,1,2,2,2,2,3,3};
y1 = new int[] {1,2,2,1,2,2,3,2,3};
x2 = new int[] {2,2,2,3,3,3,3,4,4};
y2 = new int[] {1,2,3,2,2,3,3,2,2};
sp.Reset(width,height);
sp.SetPenWidths(1.4);
sp.SetMarkerScales(2);
sp.SetMarkers(Marker.Bullet);
sp.VectorStyle = VectorStyles.Terminated|VectorStyles.Rooted|VectorStyles.NoAxes;
sp.DrawVectors(x1,y1,x2,y2);
Alternatively, a ScatterPlot could be used to draw the nodes, and the Vector chart simply to add the map of connections.
Drawing a PERT Chart
The final example assumes that the arrows represent activities of some kind, and the diagram as a whole illustrates a project plan where activities must be carried out in the correct order.

// Nodes as two arrays
x = new int[] {1,2,1,2,3,2,3,2};
y = new int[] {1,1,2,2,2,3,3,4};
// Connections as 4 arrays
x1 = new int[] {1,1,1,2,2,2,2,3,3,2};
y1 = new int[] {1,2,2,1,2,2,3,2,3,1};
x2 = new int[] {2,2,2,3,3,3,3,4,4,1};
y2 = new int[] {1,2,3,2,2,3,3,2,2,1};
sp.Reset(width,height);
sp.SetMargins(60,12,12,12);
sp.Heading = "PERT Chart with Labelled Activities";
sp.SetColors(new Color[]{Color.Navy,Color.Maroon});
sp.SetPenWidths(2);
sp.VectorStyle = VectorStyles.ArrowLines|VectorStyles.Dissected|VectorStyles.ValueTags;
sp.SetValueTags(new string[]{"One","Two","Three","Four has\n<b>two</b> lines","Five","Six","Seven\nis here","Eight","Nine","Home"});
sp.SetArrowStyle(8,24);
sp.SetValueFont("Arial",9,Color.DarkGreen);
// Draw the nodes
sp.SetMarkers(Marker.Node);
sp.SetMarkerScales(2);
sp.ScatterPlotStyle = ScatterPlotStyles.NoAxes;
sp.DrawScatterPlot(x,y);
// ... and join them with activities
sp.DrawVectors(x1,y1,x2,y2);
Here, the activities have been labelled, and the nodes drawn with a separate scatterplot. Notice the use of the Dissected style to prevent the arrows from colliding where several lines converge on the same node.
Summary
This chart has several good uses on its own, but is very likely to be combined with standard LineGraphs and ScatterPlots, typically to label bunches of points using indicator lines and notes, or to connect arbitrary points on a timeseries (for example Buy and Sell points in a historical price plot).
