2017-01-23 8 views
0

私はHighChartを使っていくつかのコンテナのメモリ使用量を表示しています。 enter image description hereHighChartで軸のスケールを変更する方法

そして、これは私が私のHighChartを作成する方法である:問題は時々スケールがMで時々Kであり、時には(怒鳴る絵のような)何もないということである

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: [] 
     }] 
    }); 

[EDIT]たぶんそれがあるので、全体のグラフを参照すると便利かもしれない: 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"; 
       } 
       } 
+0

here続きを読むあなたは、最寄りの小数点にK値を四捨五入しますか? –

+0

はい、それは仕事をすることができましたが、56600kがMで表示される方が良いし、56600MであればGになるはずなので、Mに表示する必要があります。 – Jerome

+0

私はY軸のラベルの値にアクセスする方法を述べました、あなたはそれで遊んで、あなたが望む方法を表示することができます –

答えて

0

あなたは、y軸の書式設定機能に値を切り上げでき

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' 
 
      }, 
 
      labels: { 
 
       formatter: function() { 
 
        //This will round the value, but you can do anything to this value now 
 
        return this.value.toFixed(2); 
 
       } 
 
      }, 
 
     }, 
 
     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: [] 
 
     }] 
 
    });

関連する問題