简体   繁体   English

如何使用Flot和Angular添加多个图形?

[英]How to add multiple graphs using Flot and Angular?

I am having a dataset, which consists of data for multiple days. 我有一个数据集,其中包含多天的数据。 Each day will be represented in one line. 每天将以一行显示。 This should be put in graphs using Flot.js and the data is loaded via Angularjs. 应该使用Flot.js将其放在图形中,并通过Angularjs加载数据。 On $(document).ready, there is no data existing as it is loaded from the server afterwards via HTTP. 在$ {document).ready上,不存在任何数据,因为此后它是通过HTTP从服务器加载的。 As I do not want to put all 90 days (equals to 90 lines) into one single graph, I need to split them up into separate graphs. 由于我不想将全部90天(等于90行)放入一张图表中,因此需要将它们分成单独的图表。 I have seen in various tutorials how to work with directives in Angular to achieve DOM manipulation. 我在各种教程中都看到了如何使用Angular中的指令来实现DOM操作。 However, this requires (per my understanding) that the raw DOM element is already existing on the page (such as in this tutorial: How to Integrate Flot with AngularJS? ) Actually, this is explaining the functionality of directives well, but only in case you have one data set. 但是,这(根据我的理解)要求页面上已经存在原始DOM元素(例如本教程: 如何将Flot与AngularJS集成? )实际上,这很好地解释了指令的功能,但仅在以防万一的情况下您有一个数据集。 As I need to split the data set up for more than one graph, how can I put them in different graphs, which are not existing at page creation? 当我需要分割为多个图设置的数据时,如何将它们放在页面创建时不存在的不同图中?

Thanks a lot for your help! 非常感谢你的帮助!

here plunker with very basic angular+flot implementation 这里的plunker具有非常基本的angular + flot实现

$http.get('api/data.json').then(res=>{
  $scope.name = res.data[0].label;
  let num =res.data[0].data[0][1];
  $.plot($("#placeholder"), [ [[0, 0], [1, num]] ], { yaxis: { max: 1 } });
});

This is the plunker how I was able to create the graphs on an array of data. 这就是我能够在数据数组上创建图形的方式。 The key was to use a combination of directives and ng-repeat. 关键是结合使用指令和ng-repeat。 https://plnkr.co/edit/IUvJriqbyB792R1oyhxJ?p=preview https://plnkr.co/edit/IUvJriqbyB792R1oyhxJ?p=preview

<div ng-controller="Ctrl">
        <div ng-repeat="result in results">
          <section>
            <chart ng-model="result" style="display:inline-block;width:400px;height:200px">

            </chart>
          </section>
        </div>
    </div>

Unfortunately it does not show the graphical results on plunker, but the same code does on my machine. 不幸的是,它没有在plunker上显示图形结果,但是在我的机器上却显示了相同的代码。 Thanks! 谢谢!

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

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