[英]How to make d3 title on a chart responsive?
我有將此代碼片段添加到圖表的代碼片段,如何使其具有響應性?
d3.select('#chart svg').append('text')
.attr('x', d3.select('#chart svg').node().getBoundingClientRect().width / 2)
.attr('y',20)
.attr('text-anchor', 'middle')
.style('font-size', '1.4em')
.style('fill','white')
.text(item1.chart_title);
這是小提琴: https : //jsfiddle.net/1bxe2scd/1/
附加一個類,並使用媒體查詢讓該類在不同的屏幕尺寸下表現不同:
.attr('class', 'resp-font')
.resp-font {
//media query for small
font-size: 12px;
//media query for large
font-size: 18px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.