国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

解決百度Echarts圖表坐標軸越界的方法

2019-11-19 12:41:15
字體:
來源:轉載
供稿:網友

Echarts是由百度提供的數據可視化解決方案, 可以讓我們快速實現功能豐富的圖表,官網鏈接

使用方法

1.引入echarts.min.js文件

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

創建一個掛載節點

 

將數據展示到掛載節點

生成數據, 并將數據導入到option配置對象中

    // 創建數據    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]));    }        // 創建對象option    option = {      tooltip: {        trigger: 'axis',        position: function (pt) {          return [pt[0], '10%'];        }      },      title: {        left: 'center',        text: '大數據量面積圖',      },      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:'模擬數據',          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添加到掛載節點

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

如何防止坐標軸越界

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

解決方法很簡單,只需在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>    // 創建數據    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]));    }    // 創建對象option    option = {      tooltip: {        trigger: 'axis',        position: function (pt) {          return [pt[0], '10%'];        }      },      title: {        left: 'center',        text: '大數據量面積圖',      },      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:'模擬數據',          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數據掛載到main節點    echarts.init(document.getElementById('main')).setOption(option);  </script></body></html>

小結:

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

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 任丘市| 涟水县| 龙泉市| 梁平县| 新龙县| 修武县| 邢台县| 纳雍县| 图片| 云和县| 三穗县| 峨边| 镇赉县| 微山县| 文成县| 新余市| 七台河市| 广汉市| 满城县| 寻甸| 桂平市| 南召县| 苗栗县| 微山县| 工布江达县| 德惠市| SHOW| 桂阳县| 个旧市| 大城县| 扎鲁特旗| 年辖:市辖区| 区。| 建昌县| 武汉市| 麻栗坡县| 福海县| 太白县| 集安市| 柘荣县| 青铜峡市|