javascript - 调整在 d3.js 图中绘制的图的大小
问题描述
我正在使用烧瓶开发仪表板,并且在客户端使用 d3.js。我在 html 上绘制了一个图表,我确实想将其调整为完美的大小,以便我可以创建一个侧边栏。如何调整此图的大小。这是我在 html 上绘制的 DIV 类的一部分:
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="chart" id="bargraph">
<script>
var graphs = {{plot | safe}};
Plotly.plot('bargraph',graphs,{},width = 200);
</script>
</div>
</div>
</div>
帮助我了解如何调整 d3.js 绘制的图形的大小
解决方案
如果您希望图表适合内部的所有空间,id="bargraph
您需要获取它的宽度,然后放入 Plotly 构造函数。它可能是这样的:
<script>
var graphs = {{plot | safe}};
// taking container width where we want to put chart
var getContainerWidth = document.querySelector('#bargraph').offsetWidth
// add width to our chart constructor
Plotly.plot('bargraph',graphs,{},width = getContainerWidth);
</script>
推荐阅读
- java - 在java中更改嵌套josn对象中的键名
- azure-bot-service - Azure Bot - 从 html 页面隐藏秘密直接生成令牌
- vb.net -
合并拆分数字 - node.js - 打包后节点应用程序(生产和开发模式)的意外行为(npm run dist)
- rust - `&mut []` 的生命周期是否在 Rust 的生命周期分析中得到特殊处理?
- php - 消息:未定义的偏移量:1 Codeigniter
- java - 将 json 休息响应转换为数据对象 jBPM(无法将响应转换为对象)
- node.js - docker + node.js + pm2:不能在守护进程模式下运行 docker?
- python - 应用函数而不使用应用到数据框中的每一行
- javascript - 如何创建一个完美的假 jQuery Event 对象