JavaScript D3, iterate over objects to create several pie charts within the same container iterate over objects javascript,iterate over objects js,iterate over

I have a some data that I am using to create many charts. I am using d3.nest to create a key so I can organize my charts by date. Everything seems to be working except that I cannot get the pie function to iterate over the 2 sample objects that are being created.

Here is the code snippet:

var data1 = [
    {"date":"June2013", "type":"coal", "total":20, "color": "purple", "lat": 100, "long": 100},
    {"date":"June2013", "type":"wind", "total":30, "color": "blue", "lat": 100, "long": 100},
    {"date":"June2013", "type":"nuclear", "total":40, "color": "yellow", "lat": 100, "long": 100},
    {"date":"July2013", "type":"coal", "total":50, "color": "purple", "lat": 500, "long": 200},
    {"date":"July2013", "type":"wind", "total":60, "color": "blue", "lat": 500, "long": 200},
    {"date":"July2013", "type":"nuclear", "total":70, "color": "yellow", "lat": 500, "long": 200}
];

  var energyT = d3.nest()
  .key(function(d) { 
      return d.date; 
  })
  .entries(data1); 

var arc = d3.svg.arc()
        .innerRadius(40)
        .outerRadius(50);

var pie = d3.layout.pie()
        .value(function (d){
            return d.total;
        });
        //console.log("what is the length of energyT: " + energyT.length)
        //printout:  what is the length of energyT: 2
        //it knows there are 2 objects
var arcs = svg.selectAll("arc")
        //.data(pie(energyT[0].values))
        .data(function (d, i){
            //console.log("what is i: " + JSON.stringify(energyT[i].values))
            //printout:  what is i: [{"date":"June2013","type":"coal","total":20,"color":"purple","lat":100,"long":100},...
            //it correctly passes the values of the first object 
            //but it doesn't iterate to the next
            return pie(energyT[i].values);
        })
        .enter()
        .append("svg:g")
        .attr("transform", function(d){
            return "translate(" + d.data.lat+ "," + d.data.long + ")"
        });

      arcs.append("path")
        .attr("d", arc)
        .attr("fill", function (d) {
            console.log("what is d in color " + JSON.stringify(d.data.color))
                return d.data.color;
    });
});

Also, if I pass it an exact index (.data(pie(energyT[0].values)) it will draw that chart. I don't understand how to iterated over both objects. Any advice will be appreciated.

Answer:1

I asked this question before and i had a response telling me to add a service but it doesn't work.I want to access to a variable from a controller ($scope) in an external function you can see part of ...

I asked this question before and i had a response telling me to add a service but it doesn't work.I want to access to a variable from a controller ($scope) in an external function you can see part of ...

  1. access object from another class java
  2. access object from array javascript
  3. access object from another class c#
  4. access object from array
  5. access object from another form c#
  6. access object from another thread c#
  7. access object from array php
  8. access object from json
  9. access object from js
  10. access object from php
  11. access object from class
  12. access object from form
  13. access object in javascript
  14. access object in python
  15. access object in jquery
  16. access object in list python
  17. access object in arraylist java
  18. access object with variable javascript
  19. access object in java
  20. access object in array js

I have some code that creates an accordion with a select2 element which has a class called docType. I also have jquery code to trigger an event on selecting a value of the jquery element. While this ...

I have some code that creates an accordion with a select2 element which has a class called docType. I also have jquery code to trigger an event on selecting a value of the jquery element. While this ...

I am adding footables to a table but the table has to have a tbody for each row. This is because I am adding footable sorting and filtering to an existing system that generates the html this way. It ...

I am adding footables to a table but the table has to have a tbody for each row. This is because I am adding footable sorting and filtering to an existing system that generates the html this way. It ...

  1. footable column sorting

The backend is developed by Spring MVC and hosted in tomcat. When I use postman dev tool in Chrome to test the endpoint (Restful), everything is working fine. The "Access-Control-Allow-Origin", "*" ...

The backend is developed by Spring MVC and hosted in tomcat. When I use postman dev tool in Chrome to test the endpoint (Restful), everything is working fine. The "Access-Control-Allow-Origin", "*" ...

  1. cors issue java
  2. cors issue java spring
  3. cors problem java
  4. cors issue fix in java
  5. cors issue in web api java