最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決百度Echarts圖表坐標(biāo)軸越界的方法

 更新時間:2018年10月17日 10:54:13   作者:木子昭  
Echarts是由百度提供的數(shù)據(jù)可視化解決方案, 這篇文章主要介紹了解決百度Echarts圖表坐標(biāo)軸越界的方法,非常具有實用價值,需要的朋友可以參考下

Echarts是由百度提供的數(shù)據(jù)可視化解決方案, 可以讓我們快速實現(xiàn)功能豐富的圖表,官網(wǎng)鏈接

使用方法

1.引入echarts.min.js文件

下載echarts.min.js文件,下載地址

創(chuàng)建一個掛載節(jié)點

 

將數(shù)據(jù)展示到掛載節(jié)點

生成數(shù)據(jù), 并將數(shù)據(jù)導(dǎo)入到option配置對象中

    // 創(chuàng)建數(shù)據(jù)
    var base = +new Date(1968, 9, 3);
    var oneDay = 24 * 3600 * 1000;
    var date = [];

    var data = [Math.random() * 300];

    for (var i = 1; i < 20000; i++) {
      var now = new Date(base += oneDay);
      date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
      data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
    }
    
    // 創(chuàng)建對象option
    option = {
      tooltip: {
        trigger: 'axis',
        position: function (pt) {
          return [pt[0], '10%'];
        }
      },
      title: {
        left: 'center',
        text: '大數(shù)據(jù)量面積圖',
      },
      toolbox: {
        feature: {
          dataZoom: {
            yAxisIndex: 'none'
          },
          restore: {},
          saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: date
      },
      yAxis: {
        type: 'value',
        boundaryGap: [0, '100%']
      },
      dataZoom: [{
        type: 'inside',
        start: 0,
        end: 10
      }, {
        start: 0,
        end: 10,
        handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
        handleSize: '80%',
        handleStyle: {
          color: '#fff',
          shadowBlur: 3,
          shadowColor: 'rgba(0, 0, 0, 0.6)',
          shadowOffsetX: 2,
          shadowOffsetY: 2
        }
      }],
      series: [
        {
          name:'模擬數(shù)據(jù)',
          type:'line',
          smooth:true,
          symbol: 'none',
          sampling: 'average',
          itemStyle: {
            color: 'rgb(255, 70, 131)'
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
              offset: 0,
              color: 'rgb(255, 158, 68)'
            }, {
              offset: 1,
              color: 'rgb(255, 70, 131)'
            }])
          },
          data: data
        }
      ]
    };

將option添加到掛載節(jié)點

// 將option數(shù)據(jù)掛載到main節(jié)點
echarts.init(document.getElementById('main')).setOption(option);

如何防止坐標(biāo)軸越界

上方圖表如果展示到移動版, 坐標(biāo)軸可能部分無法顯示

解決方法很簡單,只需在option中加一個配置項即可

grid:{
    containLabel: true
   },

源碼:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
     content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Echarts-Demo</title>
  <script src="./echarts.min.js"></script>
</head>
<body>
  <div id="main" style="width:100%;height:400px;"></div>
  <script>
    // 創(chuàng)建數(shù)據(jù)
    var base = +new Date(1968, 9, 3);
    var oneDay = 24 * 3600 * 1000;
    var date = [];

    var data = [Math.random() * 300];

    for (var i = 1; i < 20000; i++) {
      var now = new Date(base += oneDay);
      date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
      data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
    }

    // 創(chuàng)建對象option
    option = {
      tooltip: {
        trigger: 'axis',
        position: function (pt) {
          return [pt[0], '10%'];
        }
      },
      title: {
        left: 'center',
        text: '大數(shù)據(jù)量面積圖',
      },
      toolbox: {
        feature: {
          dataZoom: {
            yAxisIndex: 'none'
          },
          restore: {},
          saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: date
      },
      yAxis: {
        type: 'value',
        boundaryGap: [0, '100%']
      },
      dataZoom: [{
        type: 'inside',
        start: 0,
        end: 10
      }, {
        start: 0,
        end: 10,
        handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
        handleSize: '80%',
        handleStyle: {
          color: '#fff',
          shadowBlur: 3,
          shadowColor: 'rgba(0, 0, 0, 0.6)',
          shadowOffsetX: 2,
          shadowOffsetY: 2
        }
      }],
      series: [
        {
          name:'模擬數(shù)據(jù)',
          type:'line',
          smooth:true,
          symbol: 'none',
          sampling: 'average',
          itemStyle: {
            color: 'rgb(255, 70, 131)'
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
              offset: 0,
              color: 'rgb(255, 158, 68)'
            }, {
              offset: 1,
              color: 'rgb(255, 70, 131)'
            }])
          },
          data: data
        }
      ],
      grid:{
        containLabel: true
      }
    };
    // 將option數(shù)據(jù)掛載到main節(jié)點
    echarts.init(document.getElementById('main')).setOption(option);

  </script>
</body>
</html>

小結(jié):

上面實例有一個在線的版本,http://echarts.baidu.com/examples/editor.html?c=area-simple, 感興趣可以打開網(wǎng)頁, 體會一下各種配置項的用途

博主開始沒有找到正確的解決方法, 導(dǎo)致走了彎路, 最后發(fā)現(xiàn)添加一個參數(shù)就能順利解決, 這里分享給大家,希望沉迷開發(fā)的小伙伴, 能少走彎路

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

嘉善县| 常熟市| 定安县| 崇礼县| 宜春市| 揭阳市| 东阿县| 平阴县| 曲松县| 三亚市| 淳安县| 阿鲁科尔沁旗| 绥中县| 肃宁县| 景洪市| 新干县| 道真| 那曲县| 滁州市| 临沂市| 分宜县| 太仓市| 合江县| 萨嘎县| 大埔区| 伊春市| 德化县| 仪征市| 浦东新区| 汝城县| 高阳县| 平乡县| 南昌县| 城步| 秦皇岛市| 伊通| 武穴市| 招远市| 北宁市| 柞水县| 许昌县|