<script src="http://www.gojs.net/latest/samples/goSamples.js"></script>
<script src="http://www.gojs.net/latest/release/go.js"></script>
<div id="sample" style="position: relative;">
<div id="myDiagramDiv" style="background-color: white; border: solid 1px black; width: 100%; height: 700px"></div>
<div id="myOverviewDiv"></div> <!-- Styled in a <style> tag at the top of the html page -->
<p>
This sample shows an organizational chart diagram and uses an in-laid GoJS <a>Overview</a> to aid the user in navigation.
The diagram uses a <a>TreeLayout</a> featuring <a>TreeLayout.StyleLastParents</a> to allow for different alignments on the last parents.
The data was taken from the UN web site in August 2009.
</p>
<p>
A search box demonstrates one way of finding and highlighting nodes whose data includes particular strings.
Note that one can see all of the highlighted nodes in the Overview.
</p>
<input type="search" id="mySearch" onkeypress="if (event.keyCode === 13) searchDiagram()" />
<button onclick="searchDiagram()">Search</button>
<p>
To learn how to build an org chart from scratch with GoJS, see the <a href="../learn/index.html">Getting Started tutorial</a>.
</p>
<p>
If you want to have some "assistant" nodes on the side, above the regular reports,
see the <a href="orgChartAssistants.html">Org Chart Assistants</a> sample, which is a copy of this sample
that uses a custom <a>TreeLayout</a> to position "assistants" that way.
</p>
</div>
init();
function init() {
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagramDiv", // the DIV HTML element
{
// Put the diagram contents at the top center of the viewport
initialDocumentSpot: go.Spot.TopCenter,
initialViewportSpot: go.Spot.TopCenter,
// OR: Scroll to show a particular node, once the layout has determined where that node is
//"InitialLayoutCompleted": function(e) {
// var node = e.diagram.findNodeForKey(28);
// if (node !== null) e.diagram.commandHandler.scrollToPart(node);
//},
layout:
$(go.TreeLayout, // use a TreeLayout to position all of the nodes
{
treeStyle: go.TreeLayout.StyleLastParents,
// properties for most of the tree:
angle: 90,
layerSpacing: 80,
// properties for the "last parents":
alternateAngle: 0,
alternateAlignment: go.TreeLayout.AlignmentStart,
alternateNodeIndent: 20,
alternateNodeIndentPastParent: 1,
alternateNodeSpacing: 20,
alternateLayerSpacing: 40,
alternateLayerSpacingParentOverlap: 1,
alternatePortSpot: new go.Spot(0.001, 1, 20, 0),
alternateChildPortSpot: go.Spot.Left
})
});
function showMessage(s) {
document.getElementById("diagramEventsMsg").textContent = s;
}
myDiagram.addDiagramListener("ObjectSingleClicked",
function(e) {
var part = e.subject.part;
if (!(part instanceof go.Link)) alert("Clicked on " + part.data.boss);
});
// define Converters to be used for Bindings
function theNationFlagConverter(nation) {
return "https://www.nwoods.com/go/Flags/" + nation.toLowerCase().replace(/\s/g, "-") + "-flag.Png";
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.