如何使用HighChart更改轴的比例

时间:2017-01-23 07:06:06

标签: javascript highcharts

我使用HighChart显示某些容器的内存使用情况。问题是,有时尺度在K中有时在M中,有时没有任何东西(如下图所示): enter image description here

这就是我创建HighChart的方式:

var cursor = Template.currentData();
    liveChart = Highcharts.chart(cursor.chart_id, {
        title: {
            text: 'Memory usage of the controlcontainers_mongo_1'
        },
        xAxis: {
            type: 'datetime',
        },
        yAxis: {
            title: {
                text: 'usage'
            }
        },
        tooltip: {
            formatter: function() {
                return '<b>' + this.series.name + '</b><br/>' + Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>';
            }
        },
        series: [{
            type: 'line',
            name: 'memory usage',
            data: []
        }]
    });

[编辑]也许查看整个图表可能会有所帮助: enter image description here

如果有人需要,这是我的格式化程序:

formatter: function() {
                 var usage = this.value;
                 if((usage >= 1000000)&&(usage < 1000000000)){
                   return (usage/1000000).toFixed(2) + "MB";
                 }else if (usage >= 1000000000) {
                   return (usage/1000000000).toFixed(2) + "GB";
                 }else{
                   return usage + "KB";
                 }
               }

1 个答案:

答案 0 :(得分:0)

您可以在y轴格式化功能中舍入值

&#13;
&#13;
else if (val=='i'){
myservo.write(0);
delay(4000);
for(pos = 0; pos <= 90; pos += 1){
    myservo.write(pos);              
    delay(15);                       
 }
}
  else if (val=='j'){
myservo.write(0);
delay(4000);
 for(pos = 90; pos >= 0; pos -= 1){
    myservo.write(pos);              
    delay(15);                       
  }
  }
&#13;
&#13;
&#13;

了解更多here