function CreateGlyph(data, firstStationSelected ,secondStationSelected ) { var margin = { top: 50, right: 80, bottom: 50, left: 80 }, width = 700, height = 700; var gare1 = firstStationSelected var gare2 = secondStationSelected //"271007" var dataset = [{}] var data1 = [{}] var data2 = [{}] // if the secondStationSelected exists if (gare2 == null && gare1 == null){ var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) svg.append("text") .text("Veuillez sélectionner une gare") .attr("y", 50) .attr("x", 50) .attr("font-size", 20) .attr("font-family", "monospace") } if (gare2 !== null && gare1 !== null) { data.forEach(function(d){ if (d.Code_UIC == gare1){ var json = [ {uic : gare1, name : d.Nom_de_la_gare, axes : [ {indice : 'Proprete', value : +d.Proprete }, {indice : 'Securite', value : +d.Securite }, {indice : 'Communication_perturbations', value : +d.Communication_perturbations }, {indice : 'Confort_d_attente', value : +d.Confort_d_attente }, {indice : 'Commerces_restauration', value : +d.Commerces_restauration }, {indice : 'MoyenneDistance', value : 10 - +d.MoyenneDistance * 10 / 16.8 }, {indice : 'score_pmr13', value : +d.score_pmr13*10/13 }, ] }] data1 = json } if (d.Code_UIC == gare2){ var json = [ {uic : gare2, name : d.Nom_de_la_gare, axes : [ {indice : 'Proprete', value : +d.Proprete }, {indice : 'Securite', value : +d.Securite }, {indice : 'Communication_perturbations', value : +d.Communication_perturbations }, {indice : 'Confort_d_attente', value : +d.Confort_d_attente }, {indice : 'Commerces_restauration', value : +d.Commerces_restauration }, {indice : 'MoyenneDistance', value : 10 - +d.MoyenneDistance * 10 / 16.8 }, {indice : 'score_pmr13', value : +d.score_pmr13*10/13 }, ] }] data2 = json } dataset = data1.concat(data2) }) var radarChartOptions1 = { w: 100, h: 350, margin: margin, maxValue: 10, levels: 10, roundStrokes: false, color: d3.scaleOrdinal().range(["Blue","DarkOrange"]), format: '.0f', legend: { title: 'Gare', translateX: 100, translateY: 40 }, }; // Draw the chart, get a reference the created svg element : let svg_radar1 = RadarChart(".radarChart", dataset, radarChartOptions1); } //if we only select one station if (gare2 == null && gare1 !== null) { data.forEach(function(d){ if (d.Code_UIC == gare1){ var json = [ {uic : gare1, name : d.Nom_de_la_gare, axes : [ {indice : 'Proprete', value : +d.Proprete }, {indice : 'Securite', value : +d.Securite }, {indice : 'Communication_perturbations', value : +d.Communication_perturbations }, {indice : 'Confort_d_attente', value : +d.Confort_d_attente }, {indice : 'Commerces_restauration', value : +d.Commerces_restauration }, {indice : 'MoyenneDistance', value : 10 - +d.MoyenneDistance * 10 / 16.8 }, {indice : 'score_pmr13', value : +d.score_pmr13*10/13 }, ] }] dataset = json } var radarChartOptions1 = { w: 290, h: 350, margin: margin, maxValue: 10, levels: 10, roundStrokes: false, color: d3.scaleOrdinal().range(["Blue"]), format: '.0f', legend: { title: 'Gare', translateX: 100, translateY: 40 }, }; // Draw the chart, get a reference the created svg element : let svg_radar1 = RadarChart(".radarChart", dataset, radarChartOptions1); })} if (gare1 == null && gare2 !== null) { data.forEach(function(d){ if (d.Code_UIC == gare2){ var json = [ {uic : gare2, name : d.Nom_de_la_gare, axes : [ {indice : 'Proprete', value : +d.Proprete }, {indice : 'Securite', value : +d.Securite }, {indice : 'Communication_perturbations', value : +d.Communication_perturbations }, {indice : 'Confort_d_attente', value : +d.Confort_d_attente }, {indice : 'Commerces_restauration', value : +d.Commerces_restauration }, {indice : 'MoyenneDistance', value : 10 - +d.MoyenneDistance * 10 / 16.8 }, {indice : 'score_pmr13', value : +d.score_pmr13*10/13 }, ] }] dataset = json } var radarChartOptions1 = { w: 290, h: 350, margin: margin, maxValue: 10, levels: 10, roundStrokes: false, color: d3.scaleOrdinal().range(["DarkOrange"]), format: '.0f', legend: { title: 'Gare', translateX: 100, translateY: 40 }, }; // Draw the chart, get a reference the created svg element : let svg_radar1 = RadarChart(".radarChart", dataset, radarChartOptions1); })} //------------- END of JSON construction -------------------// }