如何制作显示使用/小时数的高保真

时间:2017-01-19 12:57:00

标签: meteor highcharts

我正在尝试使用实时显示容器内存使用情况的Highchart。我希望Y轴上的内存使用量(30M,28M ......)和X轴上的内存使用时间。

因此,在我的收藏中,我'读'是什么时候我使用的是Unix时间,'memory_stats {usage}'是我要显示的用法。

然后我创建Highchart的代码是:

Template.chart.onRendered(function() {
    data = [];
    var cursor = Template.currentData(),
        query = DockerStats.find(),
        initializing = true,
        liveChart;

    data = [];
    DockerStats.find().fetch().forEach(function(el) {
      var date = new Date(el.read*1000);
      // Hours part from the timestamp
      var hours = date.getHours();
      // Minutes part from the timestamp
      var minutes = "0" + date.getMinutes();
      // Seconds part from the timestamp
      var seconds = "0" + date.getSeconds();

      var time = hours + ":" + minutes + ":" + seconds;

        data.push([time, el.memory_stats.usage]);
    });
    // Create basic line-chart:
    liveChart = Highcharts.chart(cursor.chart_id, {
        title: {
            text: 'Memory usage of the controlcontainers_mongo_1'
        },
        xAxis: {
          title: {
              text: 'time reading'
          }
        },
        yAxis: {
            title: {
                text: 'usage'
            }
        },
        series: [{
            type: 'line',
            name: 'memory usage',
            data: data
        }]
    });

    // Add watchers:
    query.observe({
        added: function(addedThing) {
            if (!initializing) {
                var points = liveChart.series[0].points;
                // console.log(points)
                liveChart.series[0].addPoint([addedThing.memory_stats.usage]);
            }
        },
        removed: function(removedThing) {
            if (!initializing) {
                var points = liveChart.series[0].points;
                liveChart.series[0].addPoint([removedThing.memory_stats.usage]);
            }
        }
    });
    initializing = false;
});

但图表不是我想要的: enter image description here

有人可以帮我找到我在制作图表时遇到的错误吗?

0 个答案:

没有答案