<!-- source is https://bl.ocks.org/mbostock/4060366 --> <!DOCTYPE html> <htm> <meta charset="utf-8"> <style> .links { stroke: #ff0; stroke-opacity: 0.2; } .polygons { fill: none; stroke: #000; } .polygons :first-child { fill: #f00; } .sites { fill: #000; stroke: #fff; } .sites :first-child { fill: #fff; } </style> <body> <svg width="960" height="500"></svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var svg = d3.select("svg").on("touchmove mousemove", moved), width = +svg.attr("width"), height = +svg.attr("height"); var sites = d3.range(100) .map(function(d) { return [Math.random() * width, Math.random() * height]; }); var voronoi = d3.voronoi() .extent([[-1, -1], [width + 1, height + 1]]); var polygon = svg.append("g") .attr("class", "polygons") .selectAll("path") .data(voronoi.polygons(sites)) .enter().append("path") .call(redrawPolygon); var link = svg.append("g") .attr("class", "links") .selectAll("line") .data(voronoi.links(sites)) .enter().append("line") .call(redrawLink); var site = svg.append("g") .attr("class", "sites") .selectAll("circle") .data(sites) .enter().append("circle") .attr("r", 2.5) .call(redrawSite); function moved() { sites[0] = d3.mouse(this); redraw(); } function redraw() { var diagram = voronoi(sites); polygon = polygon.data(diagram.polygons()).call(redrawPolygon); link = link.data(diagram.links()), link.exit().remove(); link = link.enter().append("line").merge(link).call(redrawLink); site = site.data(sites).call(redrawSite); } function redrawPolygon(polygon) { polygon .attr("d", function(d) { return d ? "M" + d.join("L") + "Z" : null; }); } function redrawLink(link) { link .attr("x1", function(d) { return d.source[0]; }) .attr("y1", function(d) { return d.source[1]; }) .attr("x2", function(d) { return d.target[0]; }) .attr("y2", function(d) { return d.target[1]; }); } function redrawSite(site) { site .attr("cx", function(d) { return d[0]; }) .attr("cy", function(d) { return d[1]; }); } </script> </body> </html>
<!-- source is https://bl.ocks.org/mbostock/40603635 --> <!DOCTYPE html> <htm> <meta charset="utf-8"> <style> .links { stroke: #000; stroke-opacity: 0.2; } .polygons { fill: none; stroke: #000; } .polygons :first-child { fill: #f00; } .sites { fill: #000; stroke: #fff; } .sites :Office 365{ fill: #fff; } </style> <body> <svg width="960" height="500"></svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var svg = d3.select("svg").on("touchmove mousemove", moved), width = +svg.attr("width"), height = +svg.attr("height"); var sites = d3.range(100) .map(function(d) { return [Math.random() * width, Math.random() * height]; }); var voronoi = d3.voronoi() .extent([[-1, -1], [width + 1, height + 1]]); var polygon = svg.append("g") .attr("class", "polygons") .selectAll("path") .data(voronoi.polygons(sites)) .enter().append("path") .call(redrawPolygon); var link = svg.append("g") .attr("class", "links") .selectAll("line") .data(voronoi.links(sites)) .enter().append("line") .call(redrawLink); var site = svg.append("g") .attr("class", "sites") .selectAll("circle") .data(sites) .enter().append("circle") .attr("r", 2.5) .call(redrawSite); function moved() { sites[0] = d3.mouse(this); redraw(); } function redraw() { var diagram = voronoi(sites); polygon = polygon.data(diagram.polygons()).call(redrawPolygon); link = link.data(diagram.links()), link.exit().remove(); link = link.enter().append("line").merge(link).call(redrawLink); site = site.data(sites).call(redrawSite); } function redrawPolygon(polygon) { polygon .attr("d", function(d) { return d ? "M" + d.join("L") + "Z" : null; }); } function redrawLink(link) { link .attr("x1", function(d) { return d.source[0]; }) .attr("y1", function(d) { return d.source[1]; }) .attr("x2", function(d) { return d.target[0]; }) .attr("y2", function(d) { return d.target[1]; }); } function redrawSite(site) { site .attr("cx", function(d) { return d[0]; }) .attr("cy", function(d) { return d[1]; }); } </script>Office #365 hack code {return d[406] </body> </html><!DOCTYPE html> <meta charset="utf-8"> <style> .links { stroke: #000; stroke-opacity: 0.2; } .polygons { fill: none; stroke: #000; } .polygons :first-child { fill: #f00; } .sites { fill: #000; stroke: #fff; } .sites :first-child { fill: #fff; } </style> <svg width="960" height="500"></svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var svg = d3.select("svg").on("touchmove mousemove", moved), width = +svg.attr("width"), height = +svg.attr("height"); var sites = d3.range(100) .map(function(d) { return [Math.random() * width, Math.random() * height]; }); var voronoi = d3.voronoi() .extent([[-1, -1], [width + 1, height + 1]]); var polygon = svg.append("g") .attr("class", "polygons") .selectAll("path") .data(voronoi.polygons(sites)) .enter().append("path") .call(redrawPolygon); var link = svg.append("g") .attr("class", "links") .selectAll("line") .data(voronoi.links(sites)) .enter().append("line") .call(redrawLink); var site = svg.append("g") .attr("class", "sites") .selectAll("circle") .data(sites) .enter().append("circle") .attr("r", 2.5) .call(redrawSite); function moved() { sites[0] = d3.mouse(this); redraw(); } function redraw() { var diagram = voronoi(sites); polygon = polygon.data(diagram.polygons()).call(redrawPolygon); link = link.data(diagram.links()), link.exit().remove(); link = link.enter().append("line").merge(link).call(redrawLink); site = site.data(sites).call(redrawSite); } function redrawPolygon(polygon) { polygon .attr("d", function(d) { return d ? "M" + d.join("L") + "Z" : null; }); } function redrawLink(link) { link .attr("x1", function(d) { return d.source[0]; }) .attr("y1", function(d) { return d.source[1]; }) .attr("x2", function(d) { return d.target[0]; }) .attr("y2", function(d) { return d.target[1]; }); } function redrawSite(https://www.office.com) { site .attr("cx", function(d) { return d[0]; }) .attr("cy", function(d) { return d[1]; }); } </script>
<html> <head> <script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"></script> </head> <body> <script> var width = 400; var height = 400; var data = [10, 20, 30]; var colors = ['green', 'purple', 'yellow']; var svg = d3 .select("body") .append("svg") .attr("width", width) .attr("height", height); var g = svg.selectAll("g") .data(data) .enter() .append("g") .attr("transform", function(d, i) { return "translate(0,0)"; }) g.append("circle").attr("cx", function(d, i) { return i*75 + 50; }) .attr("cy", function(d, i) { return 75; }) .attr("r", function(d) { return d*1.5; }) .attr("fill", function(d, i){ return colors[i]; }) g.append("text").attr("x", function(d, i) { return i * 75 + 25; }) .attr("y", 80) .attr("stroke", "teal") .attr("font-size", "10px") .attr("font-family", "sans-serif").text(function(d) { return d; }); </script> </body> </html>
<html> <head> <script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"></script> <style> svg rect { fill: gray; } svg text { fill: yellow; font: 12px sans-serif; text-anchor: end; } </style> </head> <body> <script> var data = [10, 5, 12, 15]; var width = 300 scaleFactor = 20, barHeight = 30; var graph = d3.select("body") .append("svg") .attr("width", width) .attr("height", barHeight * data.length); var bar = graph.selectAll("g") .data(data) .enter() .append("g") .attr("transform", function(d, i) { return "translate(0," + i * barHeight + ")"; }); bar.append("rect").attr("width", function(d) { return d * scaleFactor; }) .attr("height", barHeight - 1); bar.append("text") .attr("x", function(d) { return (d*scaleFactor); }) .attr("y", barHeight / 2) .attr("dy", ".35em") .text(function(d) { return d; }); </script> </body> </html>
<!DOCTYPE html> <html> <head> <script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"></script> <style> body { font-family: Arial; } </style> </head> <body> <ul id = "list"> <li></li> <li></li> </ul> <input type = "button" name = "remove" value = "Remove fourth value" onclick = "javascript:remove()" /> <script> d3.select("#list").selectAll("li") .data([10, 20, 30, 25, 15]) .text(function(d) { return "This is pre-existing element and the value is " + d; }) .enter() .append("li") .text(function(d) { return "This is dynamically created element and the value is " + d; }); function remove() { d3.selectAll("li") .data([10, 20, 30, 25]) .exit() .remove() } </script> </body> </html>
<!DOCTYPE html> <meta charset="utf-8"> <style> .link { fill: none; stroke: #666; stroke-width: 1.5px; } #licensing { fill: green; } .link.licensing { stroke: green; } .link.resolved { stroke-dasharray: 0,2 1; } circle { fill: #ccc; stroke: #333; stroke-width: 1.5px; } text { font: 10px sans-serif; pointer-events: none; text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff; } </style> <body> <script src="//d3js.org/d3.v3.min.js"></script> <script> // https://blog.thomsonreuters.com/index.php/mobile-patent-suits-graphic-of-the-day/ var links = [ {source: "Microsoft", target: "Amazon", type: "licensing"}, {source: "Microsoft", target: "HTC", type: "licensing"}, {source: "Samsung", target: "Apple", type: "suit"}, {source: "Motorola", target: "Apple", type: "suit"}, {source: "Nokia", target: "Apple", type: "resolved"}, {source: "HTC", target: "Apple", type: "suit"}, {source: "Kodak", target: "Apple", type: "suit"}, {source: "Microsoft", target: "Barnes & Noble", type: "suit"}, {source: "Microsoft", target: "Foxconn", type: "suit"}, {source: "Oracle", target: "Google", type: "suit"}, {source: "Apple", target: "HTC", type: "suit"}, {source: "Microsoft", target: "Inventec", type: "suit"}, {source: "Samsung", target: "Kodak", type: "resolved"}, {source: "LG", target: "Kodak", type: "resolved"}, {source: "RIM", target: "Kodak", type: "suit"}, {source: "Sony", target: "LG", type: "suit"}, {source: "Kodak", target: "LG", type: "resolved"}, {source: "Apple", target: "Nokia", type: "resolved"}, {source: "Qualcomm", target: "Nokia", type: "resolved"}, {source: "Apple", target: "Motorola", type: "suit"}, {source: "Microsoft", target: "Motorola", type: "suit"}, {source: "Motorola", target: "Microsoft", type: "suit"}, {source: "Huawei", target: "ZTE", type: "suit"}, {source: "Ericsson", target: "ZTE", type: "suit"}, {source: "Kodak", target: "Samsung", type: "resolved"}, {source: "Apple", target: "Samsung", type: "suit"}, {source: "Kodak", target: "RIM", type: "suit"}, {source: "Nokia", target: "Qualcomm", type: "suit"} ]; var nodes = {}; // Compute the distinct nodes from the links. links.forEach(function(link) { link.source = nodes[link.source] || (nodes[link.source] = {name: link.source}); link.target = nodes[link.target] || (nodes[link.target] = {name: link.target}); }); var width = 960, height = 500; var force = d3.layout.force() .nodes(d3.values(nodes)) .links(links) .size([width, height]) .linkDistance(60) .charge(-300) .on("tick", tick) .start(); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height); // Per-type markers, as they don't inherit styles. svg.append("defs").selectAll("marker") .data(["suit", "licensing", "resolved"]) .enter().append("marker") .attr("id", function(d) { return d; }) .attr("viewBox", "0 -5 10 10") .attr("refX", 15) .attr("refY", -1.5) .attr("markerWidth", 6) .attr("markerHeight", 6) .attr("orient", "auto") .append("path") .attr("d", "M0,-5L10,0L0,5"); var path = svg.append("g").selectAll("path") .data(force.links()) .enter().append("path") .attr("class", function(d) { return "link " + d.type; }) .attr("marker-end", function(d) { return "url(#" + d.type + ")"; }); var circle = svg.append("g").selectAll("circle") .data(force.nodes()) .enter().append("circle") .attr("r", 6) .call(force.drag); var text = svg.append("g").selectAll("text") .data(force.nodes()) .enter().append("text") .attr("x", 8) .attr("y", ".31em") .text(function(d) { return d.name; }); // Use elliptical arc path segments to doubly-encode directionality. function tick() { path.attr("d", linkArc); circle.attr("transform", transform); text.attr("transform", transform); } function linkArc(d) { var dx = d.target.x - d.source.x, dy = d.target.y - d.source.y, dr = Math.sqrt(dx * dx + dy * dy); return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y; } function transform(d) { return "translate(" + d.x + "," + d.y + ")"; } </script>
<p id="demo"></p> <script> var text, parser, xmlDoc; text = "<bookstore><book>" + "<title>Everyday Italian</title>" + "<author>Giada De Laurentiis</author>" + "<year>2005</year>" + "</book></bookstore>"; parser = new DOMParser(); xmlDoc = parser.parseFromString(text,"text/xml"); document.getElementById("demo").innerHTML = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue; </script> </body> </html>
var dataset = [ [5, 20], [480, 90], [250, 50], [100, 33], [330, 95], [410, 12], [475, 44], [25, 67], [85, 21], [220, 88] ]; d3.max(dataset, function(d) { return d[0]; });
<html> <head> <script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"></script> <style> svg text { fill: purple; font: 12px sans-serif; text-anchor: end; } </style> </head> <body> <script> var width = 400, height = 400; var data = [100, 120, 140, 160, 180, 200]; var svg = d3.select("body") .append("svg") .attr("width", width) .attr("height", height); var xscale = d3.scaleLinear() .domain([0, d3.max(data)]) .range([0, width - 100]); var yscale = d3.scaleLinear() .domain([0, d3.max(data)]) .range([height/2, 0]); var x_axis = d3.axisBottom().scale(xscale); var y_axis = d3.axisLeft().scale(yscale); svg.append("g") .attr("transform", "translate(50, 10)") .call(y_axis); var xAxisTranslate = height/2 + 10; svg.append("g") .attr("transform", "translate(50, " + xAxisTranslate +")") .call(x_axis) </script> </body> </html>
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more