JavaScript d3.js - on click of legend hide/show bars google chart legend click hide,bokeh click legend to hide

          // Browser onresize event
          window.onresize = function () {
              scope.$apply();
          };


          scope.render = function (data) {
              //debugger
              //var ageNames = d3.keys(data[0]).filter(function (key) { return key !== "GateName" && key !== "QualityGateOrCheck" && key !== "GateId"; });

              var ageNames = d3.keys(data[0]).filter(function (key) {
                  return key !== "GateName" &&
                         key !== "QualityGateOrCheck" &&
                         key !== "GateId" &&
                         key !== "PercentOfCompletedByAllGates" &&
                         key !== "PercentOfCompletedByActiveGates" &&
                         key !== "PercentOfActiveByAllGates" &&
                         key !== "PercentageOfCompleteByAllGates" &&
                         key !== "PercentageOfCompleteByActiveGates" &&
                         key !== "PercentageOfActiveByAllGates" &&
                         key !== "PercentageOfCompleteByAllChecks" &&
                         key !== "PercentageOfCompleteByActiveChecks" &&
                         key !== "PercentageOfActiveByAllChecks";
              });


              data.forEach(function (d) {
                  d.ages = ageNames.map(function (name) { return { name: name, value: +d[name] }; });
              });

              var margin = { top: 20, right: 20, bottom: 30, left: 60 }, width = 1140 - margin.left - margin.right, height = 300 - margin.top - margin.bottom;
              var ticks = [0, 25, 50, 75, 100];
              var x0 = d3.scale.ordinal().rangeRoundBands([0, width - 160], .1);
              var x1 = d3.scale.ordinal();
              var y = d3.scale.linear().range([height, 0]);
              var color = d3.scale.ordinal().range(["#3366cc", "#830300", "#97be0d"]);
              var xAxis = d3.svg.axis().scale(x0).orient("bottom");
              var yAxis = d3.svg.axis().scale(y).orient("left").tickValues(ticks);
              var svg = d3.select("#barChart").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 + ")");

              x0.domain(data.map(function (d) { console.log(d.GateName); return d.GateName; }));
              x1.domain(ageNames).rangeRoundBands([0, x0.rangeBand()]);
              y.domain([0, d3.max(data, function (d) { return d3.max(d.ages, function (d) { return d.value; }); })]);
              svg.append("g").attr("class", "x axis").attr("transform", "translate(0," + height + ")").call(xAxis);
              svg.append("g").attr("class", "y axis").call(yAxis).append("text").attr("transform", "rotate(-90)").attr("y", 6).attr("dy", ".71em").style("text-anchor", "end").text("% Percentage");
              var state = svg.selectAll(".state").data(data).enter().append("g").attr("class", "g").attr("transform", function (d) { return "translate(" + x0(d.GateName) + ",0)"; });
              state.selectAll("rect").data(function (d) { return d.ages; }).enter().append("rect")
                                                       .attr("width", x1.rangeBand())
                                                       .attr("x", function (d) { return x1(d.name); })
                                                       .attr("y", function (d) { return y(d.value); })
                                                       .attr("height", function (d) { return height - y(d.value); })
                                                       .style("fill", function (d) { return color(d.name); })
                                                       .each(function (d) { this._current = d; }) // NEW
                                                       .on("mouseover", function (d) {
                                                           //debugger

                                                           //Get this bar's x/y values, then augment for the tooltip
                                                           var xPosition = parseFloat(d3.select("rect").attr("x")) + x1.rangeBand() / 2;
                                                           var yPosition = parseFloat(d3.select("rect").attr("y")) / 2 + height / 2;

                                                           //Update the tooltip position and value
                                                           d3.select("#tooltip")
                                                               .style("left", xPosition + "px")
                                                               .style("top", yPosition + "px")
                                                               .select("#toolipHeading, #value")
                                                               .text(d.name, d.value);


                                                           //Show the tooltip
                                                           d3.select("#tooltip").classed("hidden", false);

                                                       }).on("mouseout", function () {

                                                           //Hide the tooltip
                                                           d3.select("#tooltip").classed("hidden", true);

                                                       });

              state.selectAll("rect").data((function (d) { return d.ages; }))
                                     .attr("id", function (d) { return d.name; })
                                     .append("title");


              var KPILegend = ["PercentageOfComplete/AllRequirements", "PercentageOfComplete/ActiveRequirements", "PercentageOfActive/AllRequirements"];

              var legend = svg.selectAll(".legend")
                              .data(KPILegend.slice().reverse())
                              .enter().append("g")
                              .attr("class", "legend")
                              .attr("transform", function (d, i) { return "translate(0," + i * 20 + ")"; });

              legend.append("rect").attr("x", 900)
                                   .attr("width", 15)
                                   .attr("height", 15)
                                   .style("fill", color)
                                   .style('stroke', color)
                                   .on('click', function (label) {
                                       debugger

                                       var svg1 = d3.select("#barChart");

                                       svg1.selectAll('.g').selectAll('rect#PercentageOfCompleteByAllRequirements').style("display", 'block');
                                   });


          };


          //Watch 'data' and run scope.render(newVal) whenever it changes
          //Use true for 'objectEquality' property so comparisons are done on equality and not reference

          scope.$watch('data', function (chartDataNew, chartDataOld, attributes) {
              //debugger

              if (chartDataNew != undefined && chartDataOld == undefined) {
                  if (scope.data != undefined) {

                      $("#barChart").empty();
                      scope.render(scope.data);
                  }
              }
              else if (chartDataNew != undefined && chartDataOld != undefined) {
                  //debugger
                  var NewChartJSON = JSON.stringify(chartDataNew);
                  NewChartJSON = JSON.parse(NewChartJSON);

                  $.each(NewChartJSON, function (i, val) {
                      delete NewChartJSON[i].ages;
                  });

                  var OldChartJSON = JSON.stringify(chartDataOld);
                  OldChartJSON = JSON.parse(OldChartJSON);
                  NewChart = NewChartJSON;

                  var flag = false;

                  $.each(NewChart, function (index, dataNew) {
                      $.each(OldChartJSON, function (index, dataOld) {
                          if (dataNew.GateId == dataOld.GateId) {
                              if (dataNew.GateName != dataOld.GateName ||
                                  dataNew.QualityGateOrCheck != dataOld.QualityGateOrCheck ||
                                  dataNew.PercentageOfCompleteByAllRequirements != dataOld.PercentageOfCompleteByAllRequirements ||
                                  dataNew.PercentageOfCompleteByActiveRequirements != dataOld.PercentageOfCompleteByActiveRequirements ||
                                  dataNew.PercentageOfActiveByAllRequirements != dataOld.PercentageOfActiveByAllRequirements) {
                                  flag = true;
                              }
                          }
                      });
                  });

                  if (flag == true) {

                      $("#barChart").empty();
                      scope.render(scope.data);
                  }
              }
          }, true);


      }
  };

i have implemented grouped bar chart using d3.js. I have 3 items in legends. On click of a legend bar with id "xyz", it should be shown/hidden.

Using this piece of code:

svg1.selectAll('.g').selectAll('rect#PercentageOfCompleteByAllRequirements').style("display", 'block');

I'm able to fetch all the bars (rect) with the those id's. But if i apply the style it is not functioning as expected.

However, the style property (display - block) is appended to the rect element.

Some please help. Thanks in advance.

Grouped Bar Char

Answer:1

I was trying to get a dynamic dependent select list using AJAX, but unable to get the second list. Here is my code. gethint.php is working fine. I don't know where I am doing wrong. <html> ...

I was trying to get a dynamic dependent select list using AJAX, but unable to get the second list. Here is my code. gethint.php is working fine. I don't know where I am doing wrong. <html> ...

  1. visual basic select dynamic range

I have this handler that I built to handle $http requests. It looks like this: .service('ApiHandler', ['$q', '$http', '$injector', 'apiUrl', 'ErrorService', 'toastr', function ($q, $http, $injector, ...

I have this handler that I built to handle $http requests. It looks like this: .service('ApiHandler', ['$q', '$http', '$injector', 'apiUrl', 'ErrorService', 'toastr', function ($q, $http, $injector, ...

  1. angularjs interceptor responseerror
  2. angularjs http interceptor responseerror
  3. angularjs interceptor response error handling

My first question here :) I'm porting my site to Angular (I'm new to it) and wondering if I'd be able to keep my pure CSS modal dialogue box while using ui-router. In HTML it looks like this: &...

My first question here :) I'm porting my site to Angular (I'm new to it) and wondering if I'd be able to keep my pure CSS modal dialogue box while using ui-router. In HTML it looks like this: &...

I have two arrays which I want to merge. var arrayOne = [{id:1},{id:2}]; var arrayTwo = [{age: 20}, {age: 25}, {age: 22}]; Merged array should be like this [{id:1, age: 20}, {id:2, age: 25}, {age: ...

I have two arrays which I want to merge. var arrayOne = [{id:1},{id:2}]; var arrayTwo = [{age: 20}, {age: 25}, {age: 22}]; Merged array should be like this [{id:1, age: 20}, {id:2, age: 25}, {age: ...

  1. merge array objects javascript
  2. merge array objects lodash
  3. merge array objects
  4. merge array objects php
  5. merge array objects es6
  6. concat array objects javascript
  7. concat array objects
  8. merge two array objects in javascript
  9. merge 2 array objects javascript
  10. merge array of objects by key
  11. merge array of objects js
  12. merge array of objects javascript es6
  13. merge array of objects without duplicates javascript
  14. merge array of objects typescript
  15. merge two array objects in php
  16. merge array of objects by property
  17. merge array of objects by key js
  18. merge two array objects
  19. merge array of objects angular
  20. jquery merge array objects