source: Dev/trunk/d3/examples/dot/dot.html @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 2.0 KB
RevLine 
[76]1<!DOCTYPE html>
2<html>
3  <head>
4    <title>Dot Plot</title>
5    <script type="text/javascript" src="../../d3.js"></script>
6    <style type="text/css">
7
8body {
9  font: 10px sans-serif;
10}
11
12path.dot {
13  fill: white;
14  stroke-width: 1.5px;
15}
16
17rect {
18  fill: none;
19  stroke: black;
20  shape-rendering: crispEdges;
21}
22
23.x line, .y line {
24  stroke: #ccc;
25  shape-rendering: crispEdges;
26}
27
28    </style>
29  </head>
30  <body>
31    <script type="text/javascript">
32
33var data = d3.range(100).map(function(i) {
34  return {x: i / 99, y: Math.random()};
35});
36
37var w = 450,
38    h = 450,
39    p = 20,
40    x = d3.scale.linear().range([0, w]),
41    y = d3.scale.linear().range([h, 0]),
42    symbol = d3.scale.ordinal().range(d3.svg.symbolTypes),
43    color = d3.scale.category10();
44
45var vis = d3.select("body")
46  .append("svg:svg")
47    .attr("width", w + p * 2)
48    .attr("height", h + p * 2)
49  .append("svg:g")
50    .attr("transform", "translate(" + p + "," + p + ")");
51
52var xrule = vis.selectAll("g.x")
53    .data(x.ticks(10))
54  .enter().append("svg:g")
55    .attr("class", "x");
56
57xrule.append("svg:line")
58    .attr("x1", x)
59    .attr("x2", x)
60    .attr("y1", 0)
61    .attr("y2", h);
62
63xrule.append("svg:text")
64    .attr("x", x)
65    .attr("y", h + 3)
66    .attr("dy", ".71em")
67    .attr("text-anchor", "middle")
68    .text(x.tickFormat(10));
69
70var yrule = vis.selectAll("g.y")
71    .data(y.ticks(10))
72  .enter().append("svg:g")
73    .attr("class", "y");
74
75yrule.append("svg:line")
76    .attr("x1", 0)
77    .attr("x2", w)
78    .attr("y1", y)
79    .attr("y2", y);
80
81yrule.append("svg:text")
82    .attr("x", -3)
83    .attr("y", y)
84    .attr("dy", ".35em")
85    .attr("text-anchor", "end")
86    .text(y.tickFormat(10));
87
88vis.append("svg:rect")
89    .attr("width", w)
90    .attr("height", h);
91
92vis.selectAll("path.dot")
93    .data(data)
94  .enter().append("svg:path")
95    .attr("class", "dot")
96    .attr("stroke", function(d, i) { return color(i); })
97    .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; })
98    .attr("d", d3.svg.symbol()
99    .type(function(d, i) { return symbol(i); }));
100
101    </script>
102  </body>
103</html>
Note: See TracBrowser for help on using the repository browser.