2019-10-24

<style?scoped>

h2?{

??text-align:?center;

??padding:?30px;

??font-size:?18px;

}

#chart_example?{

??width:?50%;

??height:?500px;

??border:?1px?solid?red;

??margin:?0?auto;

}

</style>

<template>

??<div>

????<div?id="chart_example">

????</div>

??</div>

</template>


<script>

import?echarts?from?'echarts'

export?default?{

??data()?{

????return?{}

??},

??mounted()?{

????let?this_?=?this;

????let?myChart?=?echarts.init(document.getElementById('chart_example'));

????var?builderJson?=?{

??????"all":?10887,

??????"charts":?{//數(shù)據(jù)

????????"map":?3237,

????????"lines":?2164,

????????"bar":?7561,

????????"line":?7778,

????????"pie":?7355,

????????"scatter":?2405,

????????"candlestick":?1842,

????????"radar":?2090,

????????"heatmap":?1762,

????????"treemap":?1593,

????????"graph":?2060,

????????"boxplot":?1537,

????????"parallel":?1908,

????????"gauge":?2107,

????????"funnel":?1692,

????????"sankey":?1568

??????},

????};

????let?option?=?{

??????tooltip:?{},

??????grid:?[{

????????top:?50,

????????//?width:?'50%',

????????//?bottom:?'45%',

????????left:?10,

????????containLabel:?true

??????}],//控制圖表大小

??????xAxis:?[{

????????type:?'value',

????????max:?builderJson.all,//最大值

????????splitLine:?{

??????????show:?false

????????}

??????}],

??????yAxis:?[{

????????type:?'category',

????????data:?Object.keys(builderJson.charts),//y軸

????????axisLabel:?{

??????????interval:?0,

??????????rotate:?30//傾斜

????????},

????????splitLine:?{

??????????show:?false

????????}

??????}],

??????series:?[{

????????type:?'bar',

????????stack:?'chart',

????????z:?3,

????????label:?{

??????????normal:?{

????????????position:?'right',//數(shù)字顯示位置

????????????show:?true

??????????}

????????},

????????data:?Object.keys(builderJson.charts).map(function?(key)?{

??????????return?builderJson.charts[key];

????????})

??????}]

????}

????myChart.setOption(option);

????//建議加上以下這一行代碼,不加的效果圖如下(當(dāng)瀏覽器窗口縮小的時候)。超過了div的界限(紅色邊框)

????window.addEventListener('resize',?function?()?{?myChart.resize()?});

??},

??methods:?{},

??watch:?{},

??created()?{

??}

}

</script>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容