gpt4 book ai didi

css - D3 图表 - 在刻度值和轴路径线之间放置空间

转载 作者:行者123 更新时间:2023-12-04 14:38:11 25 4
gpt4 key购买 nike

在左下 Angular ,20012:00PM见面,值(value)观是靠在一起,看起来很拥挤。另外,点是关闭400在左上 Angular 。

我试过 padding: 30px.tick text {}但没有运气。
如何在轴路径线的刻度值之间放置一个空格?

enter image description here

.axis line {
opacity: .5;
}

.x.axis path {
opacity: 0;
}

.y.axis path {
opacity: 0;
}

.curve {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}

.graph-sheet {
display: flex;
background-color: #fafafa;
border-radius: 2px;
align-items: center;
justify-content: center;
}


.large {
width: 700px;
height: 400px;
}

.med {
width: 600px;
height: 300px;
}

.small {
width: 400px;
height: 200px;
}

.graph-title {
font-weight: 500;
text-anchor: middle;
font-size: 20px;
font-family: 'Roboto Mono',RobotoDraft,Helvetica,Arial,sans-serif;
}

.tick text {
padding: 30px;
font-size: 12px;
fill: rgba(0,0,0,.54) !important;
}
          var graph = setGraphSize(attrs.graphSize);

var margin = {top: 20, right: 30, bottom: 30, left: 30},
width = graph.width - margin.left - margin.right,
height = graph.height - margin.top - margin.bottom;

var parseDate = d3.timeParse('%H:%M');

// converts strings to date times
scope.curveData.meta.forEach(function(d) {
d.timeStamp = parseDate(d.timeStamp);
d.glucoseLevel = +d.glucoseLevel;
});

var x = d3.scaleTime()

var y = d3.scaleLinear()
.range([height, 0]);

var timeStampList = scope.curveData.meta.map(function (d) { return d.timeStamp; });

// creates X axis
var xAxis = d3.axisBottom(x)
.tickValues(timeStampList)
.tickFormat(d3.timeFormat("%I:%M %p"))

var glucoseLevelList = getTicks('glucoseLevel', scope.curveData);
var yAxis = d3.axisLeft(y).tickValues(glucoseLevelList).tickSizeInner(-width);

var curve = d3.line()
.x(function(d) { return x(d.timeStamp); })
.y(function(d) { return y(d.glucoseLevel); })
.curve(d3.curveCatmullRom.alpha(0.5));

var divEl = element[0].querySelector('div');
divEl.classList.add(attrs.graphSize);

var svg = d3.select(divEl).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 + ')');


x.domain(d3.extent(scope.curveData.meta, function(d) { return d.timeStamp; }));
y.domain(d3.extent(scope.curveData.meta, function(d) { return d.glucoseLevel; }));

// Add the scatterplot
svg.selectAll("dot")
.data(scope.curveData.meta)
.enter().append("circle")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.timeStamp); })
.attr("cy", function(d) { return y(d.glucoseLevel); });

// Add the X Axis
svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0,' + height + ')')
.call(xAxis);

// Add the Y Axis
svg.append('g')
.attr('class', 'y axis')
.call(yAxis)

// Add the value curve path.
svg.append('path')
.attr('class', 'curve')
.attr('d', curve(scope.curveData.meta));

var graphTitle = graphTitleGenerator(scope.curveData);
svg.append("text")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 4))
.attr('class', 'graph-title')
.text(graphTitle);

最佳答案

这是 D3 v4.x。因此,您必须设置 tickPadding对于您的 y 轴:

var yAxis = d3.axisLeft(y)
.tickValues(glucoseLevelList)
.tickSizeInner(-width)
.tickPadding(30);

关于css - D3 图表 - 在刻度值和轴路径线之间放置空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39338379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com