2011-12-10 70 views

回答

5

解決此問題的更好方法是在圖表上添加兩條繪圖線,指示允許的最小值和最大值爲 。

比方說,你想這個應用到Y軸,並設置最低100,最高500,你可以像這樣:

var min = 100; 
var max = 500; 

yAxis: { 

       min: min - 100, 
       max: max + 100, 
       plotLines: [{ 
        id: 'limit-min', 
        color: '#FF0000', 
        dashStyle: 'ShortDash', 
        width: 2, 
        value: min, 
        zIndex: 0 
       }, { 
        id: 'limit-max', 
        color: '#FF0000', 
        dashStyle: 'ShortDash', 
        width: 2, 
        value: max, 
        zIndex: 0 
       }] 
      } 

原因加減100到最大和最小值是因爲我們希望繪圖線在圖表上可見。

希望有所幫助。

0

爲什麼不在這個包含正常範圍的系列之後(或超過)渲染第二個帶。然後你可以很容易地看到哪些點落在該範圍之外。

-1

根據答案,我創建了一個快速代碼示例。我認爲,如果你有最低限度的紅線,你可以清楚地看到哪些點落在允許的最低限度以下。

的完整代碼:

<!DOCTYPE HTML> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <title>How to add min and max thresholds in Highcharts</title> 

     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
     <script type="text/javascript"> 
$(function() { 
    var chart; 
    $(document).ready(function() { 
     chart = new Highcharts.Chart({ 
      chart: { 
       renderTo: 'container', 
       type: 'line', 
       marginRight: 130, 
       marginBottom: 25 
      }, 
      title: { 
       text: 'Sales By Month', 
      }, 
      subtitle: { 
       text: 'Metrics', 
      }, 
      xAxis: { 
       categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
      }, 
      yAxis: { 
       title: { 
        text: 'Revenue' 
       }, 
       plotLines: [{ 
        id: 'limit-min', 
        color: '#FF0000', 
        dashStyle: 'ShortDash', 
        width: 2, 
        value: 22000, 
        zIndex: 0, 
        label : { 
         text : 'Last Year\'s Minimum Revenue' 
        } 
       }, { 
        id: 'limit-max', 
        color: '#008000', 
        dashStyle: 'ShortDash', 
        width: 2, 
        value: 32000, 
        zIndex: 0, 
        label : { 
         text : 'Last Year\'s Maximum Revenue' 
        } 
       }] 
      }, 
      tooltip: { 
       formatter: function() { 
         return '<b>'+ this.series.name +'</b><br/>'+ 
         this.x +': $'+ this.y; 
       } 
      }, 
      legend: { 
       layout: 'vertical', 
       align: 'right', 
       verticalAlign: 'top', 
       x: -10, 
       y: 100, 
       borderWidth: 0 
      }, 
      series: [{ 
       name: 'Revenue', 
       data: [21000, 24000, 27500, 33000, 29000, 26000, 19000, 21000, 25000, 29000, 23000, 18000] 
      }] 
     }); 
    }); 

}); 
     </script> 
    </head> 
    <body> 
<script src="js/highcharts.js"></script> 
<script src="js/modules/exporting.js"></script> 

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div> 

    </body> 
</html> 

工作演示here

+1

你需要在這裏記錄你的工作 - 基於鏈接的答案通常不被接受。 –

+0

您的僅鏈接答案直接導致您的網站。這不是對社區的寶貴貢獻。 – KatieK

0

根據答案,我創建了一個快速代碼示例。我認爲,如果你有最低限度的紅線,你可以清楚地看到哪些點落在允許的最低限度以下。

的完整代碼:

<!DOCTYPE HTML> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <title>How to add min and max thresholds in Highcharts</title> 

     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
     <script type="text/javascript"> 
$(function() { 
    var chart; 
    $(document).ready(function() { 
     chart = new Highcharts.Chart({ 
      chart: { 
       renderTo: 'container', 
       type: 'line', 
       marginRight: 130, 
       marginBottom: 25 
      }, 
      title: { 
       text: 'Sales By Month', 
      }, 
      subtitle: { 
       text: 'Metrics', 
      }, 
      xAxis: { 
       categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
      }, 
      yAxis: { 
       title: { 
        text: 'Revenue' 
       }, 
       plotLines: [{ 

       color: '#FF0000', 
       dashStyle: 'ShortDash', 
       width: 2, 
       value: 22, 
       zIndex: 0, 
       label : { 
        text : 'Goal' 
       } 
      }, { 
       color: '#008000', 
       dashStyle: 'ShortDash', 
       width: 2, 
       value: 10, 
       zIndex: 0, 
       label : { 
        text : 'Loss' 
       } 
      }] 
      }, 
      tooltip: { 
       formatter: function() { 
         return '<b>'+ this.series.name +'</b><br/>'+ 
         this.x +': $'+ this.y; 
       } 
      }, 
      legend: { 
       layout: 'vertical', 
       align: 'right', 
       verticalAlign: 'top', 
       x: -10, 
       y: 100, 
       borderWidth: 0 
      }, 
      series: [{ 
       name: 'Revenue', 
       data: [21000, 24000, 27500, 33000, 29000, 26000, 19000, 21000, 25000, 29000, 23000, 18000] 
      }] 
     }); 
    }); 

}); 
     </script> 
    </head> 
    <body> 
<script src="js/highcharts.js"></script> 
<script src="js/modules/exporting.js"></script> 

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div> 

    </body> 
</html> 

上編輯小提琴here工作演示。它可能會幫助你。