How to repeat equal data using data.map

1

I'm using the d3.js library and wanted it to read equal data, not overwrite the scales.

Here is the code snippet that does this, and an example of my .json file:

const months = data.map(function(d) {
            //console.log(d.month);
            return d.month;
        });
        //console.log(months);

In case the constant months is receiving an array.

const xScale = d3.scaleBand()
            .rangeRound([0, w])
            .domain(months);

But when I use the function d3.ScaleBand() it overwrites data that is the same, but I wish it did not.

svg.append('g')
    .attr('transform', 'translate(' + marginLeft + ',' + marginRight +')')
    .call(d3.axisLeft(yScale));

.json file:

[
  {"month": "January", "days": 30},
  {"month": "February", "days": 28},
  {"month": "March", "days": 31},
  {"month": "April", "days": 30},
  {"month": "May", "days": 15},
  {"month": "June", "days": 30},
  {"month": "July", "days": 22},
  {"month": "August", "days": 11},
  {"month": "September", "days": 30},
  {"month": "October", "days": 8},
  {"month": "November", "days": 30},
  {"month": "December", "days": 25},
  {"month": "September", "days": 3},
  {"month": "October", "days": 18}
]

In this case I repeated the months "September" and "October" at the end, but when drawing the scales, it draws on the existing ones.

    
asked by anonymous 18.09.2018 / 16:29

0 answers