Highcharts X轴和Y轴翻转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/84898384

一 代码

<html>
<head>
<meta charset="UTF-8" />
<title>Highcharts X轴和Y轴翻转</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://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   //图表中的x,y轴对换。
   };
   var title = {
      text: '高空大气温度'
   };
   var subtitle = {
      text: '标准大气模型'
   };
   //X轴
   var xAxis = {
      reversed: false,
      title: {
         enabled: true,
         text: '高度'
      },
      labels: {
         formatter: function () {
            return this.value + 'km';
         }
      },
      maxPadding: 0.05,
      showLastLabel: true
   };
   //Y轴
   var yAxis = {
      title: {
         text: '温度'
      },
      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: '温度',
      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>

二 测试结果

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/84898384
今日推荐