javascript - 带 D3 图的 Bootstrap Modal-Dialog

标签 javascript jquery twitter-bootstrap d3.js c3.js

第一:

我对带有图表的动态模态对话框有疑问。 代码非常简单:

https://jsfiddle.net/c2abnhja/1/

如您所见,创建的 div 容器中没有图表。但是,如果您调整窗口大小,则会使用模式对话框的正确大小正确绘制图表。 [此外,如果我手动触发调整大小事件也没关系:https://jsfiddle.net/ywaoec3d/1/ ]

第二个:

如果我为 Bootstrap 的模式对话框设置一个大小,如下所示: https://jsfiddle.net/aqs5fhha/1/ 该图永远无法获得模态内容的正确高度...但 c3.js 的文档说:

size.height

The desired height of the chart element.

If this option is not specified, the height of the chart will be
calculated by the size of the parent element it's appended to.

知道为什么图表绘制不正确吗?

提前致谢

最佳答案

我能够使用此解决您的问题:

$('#myModal').on('shown.bs.modal', function() {
    var chart = c3.generate({
        bindto: '#diagramAppend',
        data: {
            x: 'x',
            columns: [
                ['x', 30, 50, 100, 230, 300, 310],
                ['data1', 30, 200, 100, 400, 150, 250],
                ['data2', 130, 300, 200, 300, 250, 450]
            ]
        }
    });
});

基本上,发生的情况是您尝试在宽度为 0 的 div 上生成图表。等待事件 shown.bs.modal 可以让您在此时获得一个宽度

已更新JSFiddle

关于javascript - 带 D3 图的 Bootstrap Modal-Dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35475960/

相关文章:

jquery - 使用jquery转换表结构

CSS Slider 的 Tab 的事件类(Bootstrap)在第二张幻灯片上不起作用

jquery - 带有鼠标检测的水平jquery滚动也可以在div中滚动overflow-y

css - 带有居中标志的响应式 HTML5 导航栏 "popping"out

javascript - 更新提交上的范围变量并更新 Angular js中的 View

javascript - JQuery getScript() 从 curl.js 模块调用匿名函数

javascript - AngularJS 如何正确使用 ng-model 作为类?

javascript - 我想更改所有兄弟元素的样式

javascript - 如何命名我们的 JS 以与 Rails Assets 管道一起使用

javascript - 居中和隐藏图像,适合 div 大小