1
I am using the D3.js library and wanted to, when reading equal data, not overwrite when drawing scales.
Follow the code snippet that does this and an example of my file . json:
const months = data.map(function(d) {
//console.log(d.month);
return d.month;
});
//console.log(months);
In this 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 the data that are equal, but I wanted it not to do that.
svg.append('g')
.attr('transform', 'translate(' + marginLeft + ',' + marginRight +')')
.call(d3.axisLeft(yScale));
file . json:
[
{"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, he draws on top of the existing ones.