D:3 delete identical rows in table

31 views
Skip to first unread message

Peter Haas

unread,
May 19, 2018, 1:29:08 AM5/19/18
to d3-js
Häii. I'm at a project where we want to list all the different topics from the past votings in switzerland. The problem is that in the csv file the topics are named more than once, because different regions voted in the same topic. Can I automatically delete this identical rows so the list just contains the 114 votings.

Here the code: THANK YOU!


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Test Projektseite</title>
    <script type="text/javascript" src="d3/d3.min.js"></script>

    <style>
       table {
    border-collapse: collapse;
    width: 100%;
           font-family: "Arial";
}

th, td {
    text-align: left;
    padding: 8px;
}
        tr:hover {background-color: #f5f5f5;}

th {
    background-color: white;
    color: black;
}
        
th:nth-of-type(2n) {
  background: #c4c4c4;
}
    
        p.sansserif {
    font-family: Arial, Helvetica, sans-serif;
}
    </style>
    
</head>

<body>
    <h1>Test Stream 2</h1>

    <div id="chartDropdown"></div>
    <script>

      /*d3.csv("Test.csv", function(data){
            console.log(data);
            
    

        });
        
        var width = 500;
        var height = 500;
        
        var svg = d3.select("body")
            .append("svg")
            .attr("Width", width)
            .attr("height", height);
        
        svg.append("line")
            .attr("x1", 100)
            .attr("x2", 500)
            .attr("y1", 50)
            .attr("y2", 50)
            .attr("stroke", "black")*/
        
    var tabulate = function (data,columns) {
        var table = d3.select('body').append('table')
var thead = table.append('thead')
var tbody = table.append('tbody')

thead.append('tr')
  .selectAll('th')
    .data(columns)
    .enter()
  .append('th')
    .text(function (d) { return d })

var rows = tbody.selectAll('tr')
    .data(data)
    .enter()
  .append('tr')

var cells = rows.selectAll('td')
    .data(function(row) {
    return columns.map(function (column) {
    return { column: column, value: row[column] }
      })
      })
      .enter()
    .append('td')
      .text(function (d) { return d.value })

  return table;
}

d3.csv('Test.csv',function (data) {
var columns = [data.DATUM_ABSTIMMUNG,data.VORLAGE_BEZEICHNUNG]
  tabulate(data,columns)
})
       
    </script>
     
    
</body>


</html>
Reply all
Reply to author
Forward
0 new messages