简体   繁体   English

具有角度调整大小的绘图图表

[英]Flot Chart with Angular Resize

I have a flot chart successfully displayed in my HTML using a angular directive. 我使用angular指令在我的HTML中成功显示了一个flot图表。 It looks like: 看起来像:

<flot id="placeholder" dataset="dataset" options="options" height="300px" width="100%" style="width:100%;" ng-disabled="graphLoading" ng-class="{disabled:graphLoading}"></flot>

I watch for a window resize and then wish to resize the flot chart, as it doesn't do so automatically. 我注意调整窗口大小,然后希望调整flot图表的大小,因为它不会自动调整。

However resetting the datasource doesnt work and I'm somewhat lost as to what to try next. 然而,重置数据源不起作用,我有点迷失下一步尝试什么。

window.onresize = function(event) {
  console.log('refresh size of flot chart');
  refreshDataset();
}

Just looking for direction, or ideas on things I can try to debug or test to find a solution. 只是寻找方向或想法,我可以尝试调试或测试以找到解决方案。 It does seem that there is a jquery solution here http://jsfiddle.net/9x7aJ/2029/ , but I'm trying to find a angularJS solution. 似乎这里有一个jquery解决方案http://jsfiddle.net/9x7aJ/2029/ ,但我正在尝试找到angularJS解决方案。

In answer to my own question, the best solution was to use the flot.resize.js plugin for flot charts. 回答我自己的问题,最好的解决方案是使用flot.resize.js插件来获取flot图表。 I had initially included it in the index.html file, but needed to include it in the actual controllers view html file for it to get accessed, due to the nature of angularJS (I'm still learning). 我最初将它包含在index.html文件中,但由于angularJS的性质(我还在学习),需要将它包含在实际的控制器视图html文件中以便访问它。 So I dropped the jquery.flot.resize.js into my project an referenced it like so: 所以我把jquery.flot.resize.js放到我的项目中,引用它就像这样:

<script src="scripts/jquery.flot.min.js" cache="false"></script>
<script src="scripts/jquery.flot.time.js" cache="false"></script>
<script src="scripts/jquery.flot.resize.js" cache="false"></script>

The lower tech solution, was going to be a screen refresh on resize, but the resize plugin was much more elegant. 较低技术的解决方案是调整大小时的屏幕刷新,但调整大小的插件更加优雅。

Lower tech solution: 低技术解决方案:

window.onresize = function(event) {
    window.location.reload();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM