我已经使用线性渐变创建了水平连续图例。但是我的图例可以是水平的也可以是垂直的,这取决于旗帜。我如何才能使相同的图例垂直,但我不想旋转它,因为它占用了太多的空间。
const svgLegend = select(divRef.current).append("svg")
const defs = svgLegend.append("defs")
const linearGradient = defs
.append("linearGradient")
.attr("id", "linear-gradient")
.attr("x1", "0%")
.attr("x2", "100%") //since it's a horizontal linear gradient
.attr("y2", "0%");
//其他代码添加颜色
svgLegend
.append("rect")
.attr("x", 25)
.attr("y", 30)
.attr("width", 250)
.attr("height", 25)
.style("fill", "url(#linear-gradient)");
const xLeg = scaleLinear().domain([min, max]).range([10, 258]);
const axisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
svgLegend
.attr("class", "axis")
.append("g")
.attr("transform", "translate(15, 55)")
.style("font-size", "10px")
.style("font-weight", "700")
.call(axisLeg);
小提琴链接:https://jsfiddle.net/r1t60ges/3/
所需输出:
1条答案
按热度按时间os8fio9y1#