I am trying to figure out how can I customise an axis as per my req.
For example, the following code (an example notebook)
const tbl = [{ "Month": 1, "Value": 14841 }, { "Month": 2, "Value": 24467 }, { "Month": 3, "Value": 78423 }, { "Month": 4, "Value": 60213 }, { "Month": 5, "Value": 87257 }, { "Month": 6, "Value": 21543 }, { "Month": 7, "Value": 21373 }, { "Month": 8, "Value": 87363 }, { "Month": 9, "Value": 50378 }, { "Month": 10, "Value": 29714 }, { "Month": 11, "Value": 20171 }, { "Month": 12, "Value": 70059 }]
//the chart X Axis needs to start from 0
tbl.filter(a => (a.Month == 0)).length == 0 ? tbl.unshift({ "Month": 0, "Value": 0 }) : tbl
const width = 1280;
const height = 720;
//*-------2. DRAW CHART STRUCTURE (SVG HEIGHT,WIDTH, VBOX ETC)----------*//
const glblDim = {
height: height,
width: width,
margin: {
top: 20,
right: 20,
bottom: 30,
left: 50
}
}
glblDim.boundedWidth = glblDim.width - glblDim.margin.right - glblDim.margin.left;
glblDim.boundedHeight = glblDim.height - glblDim.margin.top - glblDim.margin.bottom;
//namespace
const svgns = 'http://www.w3.org/2000/svg'
const body = document.querySelector('body')
const svg = document.createElementNS(svgns, 'svg');
svg.setAttribute('xmlns', svgns);
svg.setAttribute('viewBox', `0 0 ${width} ${height}`)
body.append(svg);
const bound = document.createElementNS(svgns, 'g');
bound.setAttribute('class', 'bound');
bound.style.setProperty('transform', `translate(${glblDim.margin.left}px, ${glblDim.margin.top}px`)
svg.appendChild(bound);
//*--------------------------3. SCALE----------------------------------*//
//generate range X
const rangeX = d3.scaleTime().range([0, glblDim.boundedWidth]);
//generate scale first X
var scaleX = rangeX
.domain(d3.extent(tbl, d => d.Month))
//generate rangeY
const rangeY = d3.scaleLinear().range([glblDim.boundedHeight, 0]);
//generate scale first Y
var scaleY = rangeY
.domain(d3.extent(tbl, d => d.Value))
//-----------------4.AXES----------------------------------------------//
//generate y Axis
d3.select(bound).append('g')
.call(d3.axisLeft(scaleY))
.attr('class', 'YAxis')
.call(a => a.selectAll(".tick")
.remove())
produces this
The markup is following
but what I really want is the following
which I can achieve by manually editing the path markup as following
Is there any way within d3 to get rid of those top and bottom lines of the axis path while generating the axis?