【发布时间】:2014-09-16 20:44:17
【问题描述】:
我在让 morris.js 图表正确显示在引导模式中时遇到了一些问题。不仅尺寸缩小,而且图表不绘制。我已经四处搜索,到目前为止找不到适合我的解决方案。有人可以帮忙吗?
编辑:解决了大小问题,但仍未绘制图表。谢谢!
模态标记:
<div class="modal fade" id="clusterpulse" tabindex="-1" role="dialog" aria-labelledby="clusterpulse" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Pulse</h4>
</div>
<div class="modal-body">
<div class="col-lg-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-long-arrow-right"></i>Versions by Environment</h3>
</div>
<div class="panel-body">
<div id="morris-chart-versions"></div>
</div><!-- /.panel-body -->
</div><!-- /.panel-primary -->
</div><!-- /.col-lg-4 -->
</div><!-- /.modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div> <!-- /.modal -->
JS:
<script>
$(function () {
// Create a Bar Chart with Morris
var chart = Morris.Bar({
element: 'morris-chart-versions',
data: [0, 0], // Set initial data (ideally you would provide an array of default data)
xkey: 'd', // Set the key for X-axis
ykeys: ['test1','test2','test3'], // Set the key for Y-axis
labels: ['test1','test2','test3'], // Set the label when bar is rolled over
resize: true
stacked: true
});
// Fire off an AJAX request to load the data
$.ajax({
type: "GET",
dataType: 'json',
url: "../scripts/all_versions.php", // This is the URL to the API
})
.done(function (data) {
// When the response to the AJAX request comes back render the chart with new data
chart.setData(data);
})
.fail(function () {
// If there is no communication between the server, show an error
alert("error occured");
});
});
</script>
这就是它最终的样子:
编辑:我发现了尺寸问题。这是我标记中的“col-lg-4”。从主页上的另一个图表中将其留在那里。现在看起来像这样:
Edit2:当我从 js 中删除 'resize: true' 时。
【问题讨论】:
-
我敢打赌你得到一个 js 错误检查你的日志看看错误显示什么
-
只有 'event.returnValue 已被弃用。请改用标准 event.preventDefault()。这是已知且不相关的。
-
也许你的包括。也许它无法正确看到 .js。而且我认为 morris 需要一个 Raphael.js 才能工作?
-
是的,就是这样。我在同一页面上成功填充了其他图表。我实际上只是从 js 中删除了“resize: true”,我可以看到标签是正确的,这意味着它获取的数据只是没有绘制图表。
-
我发布了一个示例,如果您有任何问题,请告诉我。单击复选标记并投票总是有帮助:D
标签: jquery twitter-bootstrap modal-dialog morris.js