Skip to content
Kevin Warne edited this page May 2, 2016 · 1 revision

Wiki › Charts › Sankey Chart

A Sankey Chart is used to show the flow of data through links and nodes.

Example Usage

<script>
	$(document).ready(function(){

		var data = {
			data:{
				labels:{source:"Source",destination:"Expenditures"},
				columnHeaders:['header 1', 'header 2', 'header 3', 'header 4'],
				links:[
					{source:0, target:6, value:19595476, colorBy:'source'},
					{source:0, target:7, value:4074464, colorBy:'source'},
					{source:0, target:8, value:164936060, colorBy:'source'},
					{source:1, target:8, value:134007480, colorBy:'source'},
					{source:1, target:9, value:3464088, colorBy:'source'},
					{source:2, target:10, value:21000000, colorBy:'source'},
					{source:3, target:8, value:126006, colorBy:'source'},
					{source:3, target:11, value:8102863, colorBy:'source'},
					{source:4, target:8, value:2310071, colorBy:'source'},
					{source:5, target:8, value:254624, colorBy:'source'},
					{source:5, target:12, value:850000, colorBy:'source'},
					{source:8, target:13, value:170411956, colorBy:'target'},
					{source:8, target:14, value:37093519, colorBy:'target'},
					{source:8, target:15, value:33221061, colorBy:'target'},
					{source:8, target:16, value:35735864, colorBy:'target'},
					{source:8, target:17, value:17281907, colorBy:'target'},
					{source:8, target:18, value:1809376, colorBy:'target'},
					{source:8, target:19, value:6080558, colorBy:'target'}
				],
				nodes:[
					{id:0,name:"State Appropriation",shortName:"State Appropriation",colorKey:"State Appropriation"},
					{id:1,name:"Tuition",shortName:"Tuition",colorKey:"Tuition"},
					{id:2,name:"Indirect Costs",shortName:"Indirect Costs",colorKey:"Indirect Costs"},
					{id:3,name:"State Land & Permanent Fund",shortName:"State Land & Permanent Fund",colorKey:"State Land & Permanent Fund"},
					{id:4,name:"Interest, Reserves & Misc. Fees",shortName:"Interest, Reserves & Misc. Fees",colorKey:"Interest, Reserves & Misc. Fees"},
					{id:5,name:"Winrock Endowment",shortName:"Winrock Endowment",colorKey:"Winrock Endowment"},
					{id:20,name:"Transfer to HSC Instructional Programs",shortName:"Transfer to HSC Instructional Programs",colorKey:"State Appropriation"},
					{id:21,name:"Scholarship Transfer",shortName:"Scholarship Transfer",colorKey:"State Appropriation"},
					{id:8,name:"I&G Pooled Revenue",shortName:"I&G Pooled Revenue"},
					{id:9,name:"Bad Dept Allowance & Credit Card Fees",shortName:"Bad Dept Allowance & Credit Card Fees",colorKey:"Tuition"},
					{id:10,name:"Transfer to Research",shortName:"Transfer to Research",colorKey:"Indirect Costs"},
					{id:11,name:"Transfer to BR&R",shortName:"Transfer to BR&R",colorKey:"State Land & Permanent Fund"},
					{id:12,name:"Transfer to Student Aid",shortName:"Transfer to Student Aid",colorKey:"Winrock Endowment"},
					{id:13,name:"Instruction",shortName:"Instruction",colorKey:"Education and Related Expenses"},
					{id:14,name:"Operations and Maint.",shortName:"Operations and Maint.",colorKey:"Non Educational"},
					{id:15,name:"Academic Support",shortName:"Academic Support",colorKey:"Education and Related Expenses"},
					{id:16,name:"Institutional Support",shortName:"Institutional Support",colorKey:"Non Educational"},
					{id:17,name:"Student Services",shortName:"Student Services",colorKey:"Education and Related Expenses"},
					{id:18,name:"Plant-Capital",shortName:"Plant-Capital",colorKey:"Non Educational"},
					{id:19,name:"Student Aid",shortName:"Student Aid",colorKey:"Education and Related Expenses"}
				]
			}
		}

		var sankeyChart = d2b.CHARTS.sankeyChart();

		sankeyChart
			.select('.sankey-chart')
			.width($(window).width())
			.height($(window).height())
			.legendOrientation('left')
			.controls({hideLegend:{visible:true}})
			.xFormat({siPrefixed:true,separateThousands:false,units:{before:"$"},precision:4})
			.data(data)
			.update();

	})
</script>

<body style='margin:0px;'>
	<div class = 'sankey-chart'></div>
</body>

Constructor

# new d2b.CHARTS.sankeyChart()

Returns a constructor for a new sankeyChart.

Operating on the Chart

To learn how to use the common chart interface and properties (e.g. height, width, select, selection..), view the main chart page here. For sunburst-chart specific properties view below.

A sankeyChart has a number of different methods used for creation and customization of the chart. The operators return the sankeyChart, which enables concise method chaining.

Properties

# chart.legendOrientation([orientation])

If orientation is specified, sets the orientation. The following orientations are supported:

  • "top" - horizontal legend above the chart
  • "bottom" - horizontal legend below the chart
  • "left" - vertical legend to the left of the chart
  • "right" - vertical legend to the right of the chart

If orientation is not specified, returns the current orientation which defaults to "bottom".

# chart.xFormat([format])

If format is specified, sets the x value format. The format object may contain any or all of the attributes listed below:

{  
  nice:false,               // nicely format the value e.g. '4231785' => '4.231785 million'
                            // default: false, if true will override siPrefixed and searateThousands options

  siPrefixed:true,          // uses d3's "s" format type
                            // default: false, if true will override searateThousands option

  separateThousands:false,  // uses d3's "," format type
                            // default: false

  units:{                   // before and after unit strings
    before:"",              // default: ""
    after:""                // default: ""
  },

  precision:4               // sets the decimal precision
                            // default: null
}

If format is not specified, returns the current format method.

# chart.controls([controls])

If controls is specified, sets the chart controls. The controls object may contain any or all of the attributes listed below:

{
	hideLegend:{			// legend hiding checkbox
    enabled:false,  // default: false
    visible:false   // default: false
	}
}

If controls is not specified, returns the current controls object.

Data

The data passed to the chart defines how the visualization is constructed. The sankeyChart uses links and nodes to describe the individual elements on the chart. Also, you may include the optional labels/columnHeaders fields in the data set.

# chart.data([data])

If data is specified, sets the current chart data.

If data is not specified, returns the current chart data.

{
	data:{
		labels:{source:"Source",destination:"Expenditures"},
		columnHeaders:['header 1', 'header 2', 'header 3', 'header 4'],
		links:[
			{source:0, target:6, value:19595476, colorBy:'source'},
			{source:0, target:7, value:4074464, colorBy:'source'},
			{source:0, target:8, value:164936060, colorBy:'source'},
			{source:1, target:8, value:134007480, colorBy:'source'},
			{source:1, target:9, value:3464088, colorBy:'source'},
			{source:2, target:10, value:21000000, colorBy:'source'},
			{source:3, target:8, value:126006, colorBy:'source'},
			{source:3, target:11, value:8102863, colorBy:'source'},
			{source:4, target:8, value:2310071, colorBy:'source'},
			{source:5, target:8, value:254624, colorBy:'source'},
			{source:5, target:12, value:850000, colorBy:'source'},
			{source:8, target:13, value:170411956, colorBy:'target'},
			{source:8, target:14, value:37093519, colorBy:'target'},
			{source:8, target:15, value:33221061, colorBy:'target'},
			{source:8, target:16, value:35735864, colorBy:'target'},
			{source:8, target:17, value:17281907, colorBy:'target'},
			{source:8, target:18, value:1809376, colorBy:'target'},
			{source:8, target:19, value:6080558, colorBy:'target'}
		],
		nodes:[
			{id:0,name:"State Appropriation",shortName:"State Appropriation",colorKey:"State Appropriation"},
			{id:1,name:"Tuition",shortName:"Tuition",colorKey:"Tuition"},
			{id:2,name:"Indirect Costs",shortName:"Indirect Costs",colorKey:"Indirect Costs"},
			{id:3,name:"State Land & Permanent Fund",shortName:"State Land & Permanent Fund",colorKey:"State Land & Permanent Fund"},
			{id:4,name:"Interest, Reserves & Misc. Fees",shortName:"Interest, Reserves & Misc. Fees",colorKey:"Interest, Reserves & Misc. Fees"},
			{id:5,name:"Winrock Endowment",shortName:"Winrock Endowment",colorKey:"Winrock Endowment"},
			{id:20,name:"Transfer to HSC Instructional Programs",shortName:"Transfer to HSC Instructional Programs",colorKey:"State Appropriation"},
			{id:21,name:"Scholarship Transfer",shortName:"Scholarship Transfer",colorKey:"State Appropriation"},
			{id:8,name:"I&G Pooled Revenue",shortName:"I&G Pooled Revenue"},
			{id:9,name:"Bad Dept Allowance & Credit Card Fees",shortName:"Bad Dept Allowance & Credit Card Fees",colorKey:"Tuition"},
			{id:10,name:"Transfer to Research",shortName:"Transfer to Research",colorKey:"Indirect Costs"},
			{id:11,name:"Transfer to BR&R",shortName:"Transfer to BR&R",colorKey:"State Land & Permanent Fund"},
			{id:12,name:"Transfer to Student Aid",shortName:"Transfer to Student Aid",colorKey:"Winrock Endowment"},
			{id:13,name:"Instruction",shortName:"Instruction",colorKey:"Education and Related Expenses"},
			{id:14,name:"Operations and Maint.",shortName:"Operations and Maint.",colorKey:"Non Educational"},
			{id:15,name:"Academic Support",shortName:"Academic Support",colorKey:"Education and Related Expenses"},
			{id:16,name:"Institutional Support",shortName:"Institutional Support",colorKey:"Non Educational"},
			{id:17,name:"Student Services",shortName:"Student Services",colorKey:"Education and Related Expenses"},
			{id:18,name:"Plant-Capital",shortName:"Plant-Capital",colorKey:"Non Educational"},
			{id:19,name:"Student Aid",shortName:"Student Aid",colorKey:"Education and Related Expenses"}
		]
	}
}

Updating

# chart.update()

Updates the chart with the newly defined set of properties. Usually the chart will smoothly transition from the previous state to the new one.

# chart.generate()

Optionally, you may want to regenerate (empty and rebuild) the chart. This will build the new chart without an initial animation.

Clone this wiki locally