This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>D3.js demo</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v2.min.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
d3.json( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d3.json("http://localhost:8080/gdp-fr.json", function(data) { | |
var svg = d3.select("body").append("svg") | |
svg.selectAll("rect") | |
.data(data[1]) | |
.enter() | |
.append("rect") | |
.attr("y", function(d,i) { | |
// Calcule y en fonction de la propriété d.value du jeu de données | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"page":1,"pages":2,"per_page":"50","total":52},[{"indicator":{"id":"NY.GDP.MKTP.CD","value":"GDP (current US$)"},"country":{"id":"FR","value":"France"},"value":"2619685000757.11","decimal":"0","date":"2009"} | |
] | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var yScale = d3.scale.linear() | |
.domain([ | |
0, | |
d3.max( data[1], function(d) {return Math.round(d.value/1000000000) } ) | |
]) | |
.range([ | |
h, | |
h - d3.max( data[1], function(d) { return Math.round(d.value/10000000000) } ) | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var yAxis = d3.svg.axis() | |
.scale(yScale) | |
.orient("left") | |
.ticks(5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
svg.append("g") | |
.attr("class", "yaxis") | |
.attr("transform", "translate(40,0)") | |
.call(yAxis) | |
.append("text") | |
.attr("transform", "rotate(-90)") | |
.attr("y", 6) | |
.attr("dy", ".71em") | |
.style("text-anchor", "end") | |
.text("PIB de la France (Md de $)"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="/socket.io/socket.io.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connection au serveur | |
var socket = io.connect('http://localhost:8081'); | |
// Listener sur la réception de données du serveur | |
socket.on('info serveur', function(dataFromServer) { | |
// Traitement du message reçu | |
}); | |
// Envoi de données vers le serveur | |
socket.emit('donnees saisies', dataToServer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')() | |
, server = require('http').createServer(app) | |
, io = require('socket.io').listen(server); | |
server.listen(8081); | |
app.get('/', function handler(req, res) { | |
res.sendfile(__dirname + '/client.html'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.sockets.on('connection', function(socket) { | |
// Un client se connecte | |
console.log('Connexion'); | |
socket.on('saisie', function(data) { | |
// Message reçu du client | |
// On le ré-expédie vers le client | |
socket.emit('info', { message: '>>ECHO : ' + data }); | |
}); | |
}); |
OlderNewer