Highcharts - 帶有反轉軸的樣條曲線圖



下面是一個帶有反轉軸的樣條曲線圖的示例。

我們已經在 Highcharts 配置語法 章節中看到了用於繪製圖表的配置。現在,我們將討論帶有反轉軸的樣條曲線圖的示例。

配置

將圖表型別配置為基於樣條曲線。chart.type 會決定圖表的系列型別。這裡,預設值為“line”。

配置軸要反轉。當 true x 軸 為垂直的,y 軸 為水平的 - 如果圖表中存在條形系列,則它會被反轉。這裡,預設值為 false。

圖表

var chart = {
   type: 'spline',
   inverted: true
}; 

示例

highcharts_spline_inverted.htm

<html>
   <head>
      <title>Highcharts Tutorial</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script src = "https://code.highcharts.com/highcharts.js"></script>  
   </head>
   
   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
      <script language = "JavaScript">
         $(document).ready(function() {  
            var chart = {
               type: 'spline',
               inverted: true
            }; 
            var title = {
               text: 'Atmosphere Temperature by Altitude'   
            };
            var subtitle = {
               text: 'According to the Standard Atmosphere Model'
            };
            var xAxis = {
               reversed: false,
               title: {
                  enabled: true,
                  text: 'Altitude'
               },
               labels: {
                  formatter: function () {
                     return this.value + 'km';
                  }
               },
               maxPadding: 0.05,
               showLastLabel: true
            };
            var yAxis = {
               title: {
                  text: 'Temperature'
               },
               labels: {
                  formatter: function () {
                     return this.value + '\xB0';
                  }
               },
               lineWidth: 2
            };
            var legend = {
               enabled: false 
            };
            var tooltip = {
               headerFormat: '<b>{series.name}</b><br/>',
               pointFormat: '{point.x} km: {point.y}\xB0C'
            };
            var plotOptions = {
               spline: {
                  marker: {
                     enable: false
                  }
               }
            };
            var series = [{
               name: 'Temperature',
               data: [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1],
                  [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]
            }];      
   
            var json = {};
            json.chart = chart;
            json.title = title;
            json.subtitle = subtitle;
            json.legend = legend;
            json.tooltip = tooltip;
            json.xAxis = xAxis;
            json.yAxis = yAxis;  
            json.series = series;
            json.plotOptions = plotOptions;
            $('#container').highcharts(json);
  
         });
      </script>
   </body>
   
</html>

結果

驗證結果。

highcharts_line_charts.htm
廣告
© . All rights reserved.