D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
MTClass
Full window
Github gist
// source http://jsbin.com/sivozey
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Trying to build a legend</title <body> <style> <svg width="960" height="500"></svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var svg = d3.select("body").append("svg")... // add legend to svg. var legend = svg.append('g') .attr('class', 'legend') .attr('transform', 'translate(50, 30)') .style('font-size', '12px') .call(d3.legend); var svg = d3.select("svg"), margin = {top: 20, right: 80, bottom: 30, left: 50}, width = svg.attr("width") - margin.left - margin.right, height = svg.attr("height") - margin.top - margin.bottom, g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var parseTime = d3.timeParse("%Y%m%d"); var x = d3.scaleTime().range([0, width]), y = d3.scaleLinear().range([height, 0]), z = d3.scaleOrdinal(d3.schemeCategory10); legend = svg.append("g") .attr("class","legend") .attr("transform","translate(50,30)") .style("font-size","12px") .call(d3.legend) </script> var svg = d3.select("svg"), margin = {top: 20, right: 80, bottom: 30, left: 50}, width = svg.attr("width") - margin.left - margin.right, height = svg.attr("height") - margin.top - margin.bottom, g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var parseTime = d3.timeParse("%Y%m%d"); var x = d3.scaleTime().range([0, width]), y = d3.scaleLinear().range([height, 0]), z = d3.scaleOrdinal(d3.schemeCategory10); <script id="jsbin-source-html" type="text/html"><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Trying to build a legend</title <body> <style> <svg width="960" height="500"></svg> <script src="//d3js.org/d3.v4.min.js"><\/script> <script> var svg = d3.select("body").append("svg")... // add legend to svg. var legend = svg.append('g') .attr('class', 'legend') .attr('transform', 'translate(50, 30)') .style('font-size', '12px') .call(d3.legend); var svg = d3.select("svg"), margin = {top: 20, right: 80, bottom: 30, left: 50}, width = svg.attr("width") - margin.left - margin.right, height = svg.attr("height") - margin.top - margin.bottom, g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var parseTime = d3.timeParse("%Y%m%d"); var x = d3.scaleTime().range([0, width]), y = d3.scaleLinear().range([height, 0]), z = d3.scaleOrdinal(d3.schemeCategory10); legend = svg.append("g") .attr("class","legend") .attr("transform","translate(50,30)") .style("font-size","12px") .call(d3.legend) <\/script> var svg = d3.select("svg"), margin = {top: 20, right: 80, bottom: 30, left: 50}, width = svg.attr("width") - margin.left - margin.right, height = svg.attr("height") - margin.top - margin.bottom, g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var parseTime = d3.timeParse("%Y%m%d"); var x = d3.scaleTime().range([0, width]), y = d3.scaleLinear().range([height, 0]), z = d3.scaleOrdinal(d3.schemeCategory10); </body> </html></script> </body> </html>
Modified
http://d3js.org/d3.v4.min.js
to a secure url
https://d3js.org/d3.v4.min.js
https://d3js.org/d3.v4.min.js