【问题标题】:Flot Chart with Angular Resize带有角度调整大小的浮动图表
【发布时间】:2015-02-17 07:42:20
【问题描述】:

我使用 angular 指令在我的 HTML 中成功显示了一个浮点图表。 它看起来像:

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

我观察窗口调整大小,然后希望调整浮动图表的大小,因为它不会自动这样做。

但是重置数据源不起作用,我有点不知道接下来要尝试什么。

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

只是寻找方向或想法,我可以尝试调试或测试以找到解决方案。这里http://jsfiddle.net/9x7aJ/2029/似乎有一个jquery解决方案,但我正在尝试找到一个angularJS解决方案。

【问题讨论】:

    标签: javascript angularjs html angularjs-directive


    【解决方案1】:

    在回答我自己的问题时,最好的解决方案是将 flot.resize.js 插件用于浮点图。我最初将它包含在 index.html 文件中,但由于 angularJS 的性质(我仍在学习),需要将其包含在实际的控制器视图 html 文件中才能访问它。所以我将 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>
    

    较低技术的解决方案是在调整大小时刷新屏幕,但调整大小插件要优雅得多。

    低技术解决方案:

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

    【讨论】:

    • 您能否提供更多有关其工作原理的信息?你还在指令中将 height 属性设置为 300px 吗?
    猜你喜欢
    • 1970-01-01
    • 2016-02-02
    • 2016-03-21
    • 2013-05-24
    • 2011-09-14
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多