JavaScript how to show bar chart based on multiple filter values in D3 js excel show chart based on cell value,ssrs show chart

I have made a bar chart based on revenue(x axis) and country(y axis) basis.My bar chart is done but I want to select multiple values of country from a dropdown and according to those values the bars of only that country should be shown others hide...For single selection i have done but for multiple values of country how to filter and show in D3 Js bar chart I am stuck. The localDataJson contains the data:

localdatajson=[
           {"Country";"USA","Revenue":"12","TurnOver":"16"},
           {"Country";"Brazil","Revenue":"4.5","TurnOver":"16"},
           {"Country";"Belzium","Revenue":"4.8","TurnOver":"16"},
           {"Country";"Britain","Revenue":"20","TurnOver":"16"},
           {"Country";"Canada","Revenue":"6.5","TurnOver":"16"},
           {"Country";"DenMark","Revenue":"7.5","TurnOver":"16"}
         ]

text parameter would be an array in case of multiple selection like for eg. text=["USA","Brazil","Britain"] I want to show bars only for these three countries... Here is my code

 function revenueBar(localDataJson, text) {
    var w = 400;
    var h = 400;
    var barPadding = 1;
    var maxRevenue = 0;
    var maxTurnOver = 0;
    var padding = {
        left: 45, right: 10,
        top: 40, bottom: 60
    }

    var maxWidth = w - padding.left - padding.right;
    var maxHeight = h - padding.top - padding.bottom;
    for (var j = 0; j < localDataJson.length; j++) {
        if (localDataJson[j].Revenue > maxRevenue) {
            maxRevenue = localDataJson[j].Revenue;
        }

    }
    for (var j = 0; j < localDataJson.length; j++) {
        if (localDataJson[j].TurnOver > maxTurnOver) {
            maxTurnOver = localDataJson[j].TurnOver;
        }

    }
    var convert = {
        x: d3.scale.ordinal(),
        y: d3.scale.linear()
    };
    // Define your axis
    var axis = {
        x: d3.svg.axis().orient('bottom')
        //y: d3.svg.axis().orient('left')
    };

    // Define the conversion function for the axis points
    axis.x.scale(convert.x);
   // axis.y.scale(convert.y);

    // Define the output range of your conversion functions
    convert.y.range([maxHeight, 0]);
    convert.x.rangeRoundBands([0, maxWidth]);

    convert.x.domain(localDataJson.map(function (d) {
        return d.Country;
    })
    );
    convert.y.domain([0, maxRevenue]);
    $('#chartBar').html("");
    var svg = d3.select("#chartBar")
               .append("svg")
               .attr("width", w)
               .attr("height", h);
    // The group node that will contain all the other nodes
    // that render your chart
    $('.bar-group').html("");
    var chart = svg.append('g')
                         .attr({
                             class: 'container',
                             transform: function (d, i) {
                                 return 'translate(' + padding.left + ',' + padding.top + ')';
                             }
                         });

    chart.append('g') // Container for the axis
                .attr({
                    class: 'x axis',
                    transform: 'translate(0,' + maxHeight + ')'
                })
               .call(axis.x)
                .selectAll("text")
                             .attr("x", "-.8em")
                             .attr("y", ".15em")
                     .style("text-anchor", "end")
                            .attr("transform", "rotate(-65)");// Insert an axis inside this node
    $('.axis path').css("fill", "none");
    chart.append('g') // Container for the axis
       // .attr({
       //     class: 'y axis',
       //     height: maxHeight,

       // })
       //.call(axis.y);

    var bars = chart
         .selectAll('g.bar-group')
         .data(localDataJson)
         .enter()
         .append('g') // Container for the each bar
         .attr({
             transform: function (d, i) {
                 return 'translate(' + convert.x(d.Country) + ', 1)';
             },
             class: 'bar-group'
         });

    //Here goes filter thing ,bar of filter values will be shown others hide
    if (text != "All" && text != "Clear Filter") {

        svg.selectAll('g.bar-group')
          .filter(function (d) {
                 return text != d.Country;
          })
          .attr("display", "none");

        svg.selectAll('g.bar-group')
                  .filter(function (d) {
                  return text == d.Country;
                   })
            .attr("display", "inline");
    }
    var color = d3.scale.category20();
   // var color = d3.scale.ordinal()
                 // .range(['#f1595f', '#79c36a', '#599ad3', '#f9a65a', '#9e66ab','#cd7058']);
    bars.append('rect')
                .attr({
                    y: maxHeight,
                    height: 0,
                    width: function (d) { return convert.x.rangeBand(d) - 3; },
                    class: 'bar'
                })
                .transition()
                .duration(1500)
                .attr({
                    y: function (d, i) {
                        return convert.y(d.Revenue);
                    },
                    height: function (d, i) {
                        return maxHeight - convert.y(d.Revenue);
                    }
                })
                .attr("fill", function (d, i) {
                    // return color(i);
                    return color(d.Country);
                })
   // for (var i = 0; i < text.length; i++) {

   // }


    svg.append("text")
     .attr("x", (w + padding.left + padding.right) / 2)
     .attr("y", 25)
     .attr("class", "title")
     .attr("text-anchor", "middle")
     .text("Revenue Bar Chart")
    ;

    var svgs = svg.select("g.container").selectAll("text.label")
  //  svgs.selectAll("text")
      .data(localDataJson)

      .enter()
      .append("text")
      .classed("label", true)
        //.transition()        // <-- This is new,
      // .duration(5000)
      .text(function (d) {
          return (d.Revenue);
      })
      .attr("text-anchor", "middle")
      //// Set x position to the left edge of each bar plus half the bar width
      .attr("x", function (d, i) {
          // return (i * (w / localDataJson.length)) + ((w / localDataJson.length - barPadding) / 2);
          return convert.x(d.Country) + (convert.x.rangeBand(d) - 3) / 2;
      })
     .attr({
         y: function (d, i) {
            return convert.y(d.Revenue) +20;
            // return maxHeight;
         },

     })
   .attr("font-family", "sans-serif")
    .attr("font-size", "13px")
    .attr("fill", "white")


}
Answer:1

I have this array var arr1 = [{id: 1, name: "lorem"}, {id: 1, name: "ipsum"}, {id: 2, name: "dolor"}] as you can see here the first 2 indexs they got same id, I want the ouput to be something like ...

I have this array var arr1 = [{id: 1, name: "lorem"}, {id: 1, name: "ipsum"}, {id: 2, name: "dolor"}] as you can see here the first 2 indexs they got same id, I want the ouput to be something like ...

  1. merge object array javascript
  2. merge object array php
  3. merge object array
  4. merge object array js
  5. merge object arrays java
  6. merge object array typescript
  7. merge object array c#
  8. merge array object jquery
  9. object merge array property
  10. merge two object arrays javascript
  11. merge 2 object arrays javascript
  12. merge two object arrays typescript
  13. powershell merge object arrays
  14. lodash merge object arrays
  15. merge two object arrays php
  16. merge two object arrays java
  17. merge object into array
  18. merge two object arrays
  19. merge two object arrays c#
  20. merge object inside array

I am using class="animationName" instead of ng-animate, as it has changed with 1.2. However I can't seem to get the below to work. What am I missing? CSS: .move-animation.ng-move { -webkit-...

I am using class="animationName" instead of ng-animate, as it has changed with 1.2. However I can't seem to get the below to work. What am I missing? CSS: .move-animation.ng-move { -webkit-...

  1. angular animate not working
  2. angular animate doesn't work
  3. angular animate transition not working
  4. angular animate delay not working

I'm trying to figure out why this is returning false: var goodUsers = [ { id: 1 }, { id: 2 }, { id: 3 }, ]; var testUsers = [ { id: 1 }, { id: 2 }, { id: 3 } ]; console....

I'm trying to figure out why this is returning false: var goodUsers = [ { id: 1 }, { id: 2 }, { id: 3 }, ]; var testUsers = [ { id: 1 }, { id: 2 }, { id: 3 } ]; console....

The script below contains some URLs in links array. The function gatherLinks() is used to gather more URLs from sitemap.xml of the URLs in links array. Once the links array has enough URLs (decided by ...

The script below contains some URLs in links array. The function gatherLinks() is used to gather more URLs from sitemap.xml of the URLs in links array. Once the links array has enough URLs (decided by ...

  1. phantomjs does not exist in the namespace openqa.selenium
  2. phantomjs does not execute javascript
  3. phantomjs does not appear to be installed
  4. phantomjs does not render
  5. phantomjs does not work
  6. phantomjs doesn't execute javascript
  7. phantomjs doesn't load javascript
  8. phantomjs doesn't load page
  9. phantomjs doesn't work
  10. phantomjs js doesn't
  11. phantomjs.exe file does not exist
  12. phantomjs binary does not exist
  13. phantomjs click does not work
  14. phantomjs render doesn't work
  15. phantomjs does not work with selenium java
  16. phantomjs proxy doesn't work