如何使气泡图随机位置
How to make Bubble Chart Random Position
我想让气泡的位置是随机的,而不是人们需要设置y和x的位置。
这里是示例气泡图的链接
http://codepen.io/anon/pen/LowKD
这里是js脚本
$(document).ready(function() {
$('.graph-bar').each(function() {
var dataWidth = $(this).data('value');
$(this).css("width", dataWidth + "%");
});
});
// Positioning of .bubbleChart
$(document).ready(function() {
$('.chart-bubble').each(function() {
// Bubble Size
var bubbleSize = $(this).data('value');
$(this).css("width", function() {
return (bubbleSize * 10) + "px"
});
$(this).css("height", function() {
return (bubbleSize * 10) + "px"
});
// Bubble Position
var posX = $(this).data('x');
var posY = $(this).data('y');
$(this).css("left", function() {
return posX - (bubbleSize * 0.5) + "%"
});
$(this).css("bottom", function() {
return posY - (bubbleSize * 0.5) + "%"
});
});
});
我想要这个气泡图来随机定位
<div data-value="7" data-label="500" data-x="50" data-y="50" class="chart-bubble"></div>
所以我不必设置数据x和y,因为我想在用户填充值
我会使用Math.random()
。它给你一个0到1之间的随机数,你只需要把它乘以你的范围(在你的情况下,我想它是你的窗口的宽度和高度)。
查看random()文档。
相关文章:
- 如何克隆图像并将其放置在随机位置
- 开玩笑:测试数组的随机位置
- 谷歌地图API使用Math.random获取随机位置 - JS
- 返回包含随机位置元素的数组
- 在随机位置与空格匹配字符串
- 如何使气泡图随机位置
- 启动HTML5<音频>在随机位置
- 使用jQuery将文本按字面顺序分解到随机位置
- 在HTML5蛇游戏中为食物生成随机位置时发生未捕获的TypeError
- 将图像定位在随机位置
- 如何对齐一个旋转的轮子停止在中心位置,而不是使用javascript随机位置
- 在Safari iOS10中,在iframe中调用element.focus()将父页面滚动到随机位置
- 使用javaScript在随机位置显示图像时遇到麻烦
- 如何让我的缩略图显示在随机位置(在存档页面wordpress)
- 附加内容的随机位置与jQuery
- 具有随机位置的数组
- 我如何在js中分散随机位置的图像
- 将字符串插入到另一个字符串中的随机位置
- 图像的随机位置
- 工具提示显示在随机位置