我有这个代码Fiddle ,它呈现一个条形图,图像位于每个条形的顶部。
对于较小的值,我不希望图像在条形图内呈现,而是希望它位于条形图的顶部/外部。例如,第 4 个栏会在栏的顶部而不是内部显示图像。是否有一种巧妙的方法来添加条件,因为条形图将使用不断变化的数据,因此需要一种方法来确定哪些条形将在外部显示图像,哪些将在内部显示?
var w = 750;
var h = 300;
var barPadding = 2;
var dataset2 = [{
"category": "A",
"Value": 18,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "B",
"Value": 15,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "C",
"Value": 13,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "D",
"Value": 2,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "E",
"Value": 12,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "F",
"Value": 15,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "G",
"Value": 20,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "H",
"Value": 25,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
},
{
"category": "H",
"Value": 30,
"URLimage": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Baseball.svg/520px-Baseball.svg.png"
}
]
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
MMMHUHU
相关分类