From 82abbb3fc3d9b43ce8d4219626fe79505a6988d1 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 9 Feb 2023 23:25:19 +0100 Subject: [PATCH] graph donut report --- donut/data.csv | 4 ++ donut/graphs.mjs | 105 ++++++++++++++++++++++++++++++++++++++++++++++ donut/index.html | 16 +++++++ donut/style.css | 3 ++ graphs/data.csv | 0 graphs/graphs.mjs | 0 graphs/index.html | 0 graphs/style.css | 0 8 files changed, 128 insertions(+) create mode 100644 donut/data.csv create mode 100644 donut/graphs.mjs create mode 100644 donut/index.html create mode 100644 donut/style.css create mode 100644 graphs/data.csv create mode 100644 graphs/graphs.mjs create mode 100644 graphs/index.html create mode 100644 graphs/style.css diff --git a/donut/data.csv b/donut/data.csv new file mode 100644 index 0000000..b68def2 --- /dev/null +++ b/donut/data.csv @@ -0,0 +1,4 @@ +letter,cout +12,50 +15,55 +30,85 \ No newline at end of file diff --git a/donut/graphs.mjs b/donut/graphs.mjs new file mode 100644 index 0000000..683df05 --- /dev/null +++ b/donut/graphs.mjs @@ -0,0 +1,105 @@ +//propriétés visuelles du graphique +var margin = { + top: 20, + right: 20, + bottom: 30, + left: 60 +}; + +var width = 600 - margin.left - margin.right; +var height = 300 - margin.top - margin.bottom; + +//la portée de l'axe des X +var x = d3.scale.ordinal() + .rangeRoundBands([0, width], .1, 1); + +var xAxis = d3.svg.axis() + .scale(x) + .orient("bottom"); + +//la portée de l'axe des X +var y = d3.scale.linear() + .range([height, 0]); + +var currencyFormat = d3.format("$"); +var yAxis = d3.svg.axis() + .scale(y) + .orient("left") + .tickFormat(currencyFormat); + +//création de l'élément SVG du document +var svg = d3 + .select("body") + .append("svg") + .attr("width", width + margin.left + margin.right) + .attr("height", height + margin.top + margin.bottom) + .append("g") + .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); + +d3.csv("data.csv", function (error, data) { + //calcul du domaine de l'axe X + x.domain(data.map(function (d) { + return d.letter; + })); + + //calcul du domaine de l'axe Y + y.domain([0, d3.max(data, function (d) { + return d.cout; + })]); + + //mise en place des barres pour chacune des lettres + var bar = svg.selectAll("g") + .data(data) + .enter() + .append("g") + .attr("class", "bob"); + + bar.append("rect") + .attr("class", "bar") + .attr("fill", function (d) { + return d.couleur; + }) + //positonnement sur l'axe des X de la barre + .attr("x", function (d) { + return x(d.letter) - 50; + }) + //positonnement sur l'axe des Y de la barre + .attr("y", function (d) { + return y(d.cout); + }) + //largeur de la barre + .attr("width", x.rangeBand() + 10) + //hauteur de la barre + .attr("height", function (d) { + return height - y(d.cout); + }); + + bar.append("text") + .attr("class", "bar-color") + .attr("x", function (d) { return x(d.letter) - 17 }) + .attr("y", function (d) { + return y(d.cout) - 10; + }) + .attr("dy", ".35em") + .attr("fill", "black") + .text(function (d) { return currencyFormat(d.cout); }); + + //positionnement de l'axe des X + svg.append("g") + .attr("class", "x axis") + .attr("transform", "translate(-50," + height + ")") + .call(xAxis); + + //positionnement de l'axe des Y + svg.append("g") + .attr("class", "y axis") + .call(yAxis) + + //Ajout du petit texte "fréquence" + .append("text") + .attr("transform", "rotate(-90)") + .attr("y", 6) + .attr("dy", ".71em") + .style("text-anchor", "end") + .text("Coûts"); +}); \ No newline at end of file diff --git a/donut/index.html b/donut/index.html new file mode 100644 index 0000000..5613cab --- /dev/null +++ b/donut/index.html @@ -0,0 +1,16 @@ + + + + + + + + + + +

+ Rapport de tâches +

+
+ + diff --git a/donut/style.css b/donut/style.css new file mode 100644 index 0000000..c88d1d3 --- /dev/null +++ b/donut/style.css @@ -0,0 +1,3 @@ +.bob{ + fill: cadetblue; +} \ No newline at end of file diff --git a/graphs/data.csv b/graphs/data.csv new file mode 100644 index 0000000..e69de29 diff --git a/graphs/graphs.mjs b/graphs/graphs.mjs new file mode 100644 index 0000000..e69de29 diff --git a/graphs/index.html b/graphs/index.html new file mode 100644 index 0000000..e69de29 diff --git a/graphs/style.css b/graphs/style.css new file mode 100644 index 0000000..e69de29