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

首頁(yè) > 編程 > JavaScript > 正文

詳解ECharts使用心得總結(jié)

2019-11-19 18:39:27
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

前言

上周項(xiàng)目組要臨時(shí)給客戶做一個(gè)演示的原型,首頁(yè)設(shè)計(jì)的是一個(gè)中國(guó)地圖,本來(lái)打算用谷歌的地圖,但是,做出來(lái)之后,整體的效果看起來(lái)太差了,最后就在網(wǎng)上搜相關(guān)的地圖呈現(xiàn)的控件,然后就找到了這個(gè)ECharts報(bào)表呈現(xiàn)組件,挺不錯(cuò)的一個(gè)組件,而且地圖數(shù)據(jù)都是離線的,真心很贊。但是,使用起來(lái)卻頗費(fèi)了一番工夫。所以就把使用中的一些心得體會(huì)跟大家分享一下。

1.    插件的下載

以下是ECharts的下載鏈接,需要注意的是ECharts內(nèi)部也是依賴于另一個(gè)插件的叫ZRender,當(dāng)然對(duì)于大部分圖表而言不需要ZRender的,但是對(duì)于地圖控件及其他復(fù)雜的呈現(xiàn)控件而已都是需要ZRender的。為了避免不要的問(wèn)題出現(xiàn),建議大家在下載ECharts時(shí)同時(shí)也要下載ZRender。

ECharts下載地址: http://echarts.baidu.com/

ZRender下載地址:http://ecomfe.github.io/zrender/index.html

下載之后解壓各自的文件目錄結(jié)構(gòu)如下:

ECharts:

      

ZRender:

2.    插件的引用

首先,新建一個(gè)Web應(yīng)用程序,然后添加剛剛下載的文件,具體的目錄結(jié)構(gòu)如下:

這里有以下幾點(diǎn)需要說(shuō)明:

1、所有的跟ECharts有關(guān)的文件全部都在echarts文件夾下

2、echarts文件夾的內(nèi)容分為兩部分

1)  一部分是以echarts開(kāi)頭的js文件,這些文件全部來(lái)自于1.中的ECharts文件目錄中的js文件夾下的文件,也就是1.中的圖中紅框標(biāo)注的js下的文件。如下:

2) 另一部分是一個(gè)名為zrender的文件夾,這里需要特別注意的是該文件夾的命名必須為zrender,因?yàn)樵趀charts的js文件中對(duì)zrender的引用都是以zrender為根目錄的,zrender文件夾的內(nèi)容即為1.中zrender文件目錄中的src文件夾下的內(nèi)容,如下:

3.    在頁(yè)面中的具體使用

按照上邊的步驟配置過(guò)之后,我們就可以在頁(yè)面中引用了,這里我主要是演示地圖控件的使用方式,因?yàn)榈貓D的引用跟其他的基本圖形的引用不太一樣。其他的圖形的呈現(xiàn)也會(huì)做一個(gè)簡(jiǎn)要的演示。

3.1 MapChart

首先在跟2中的echarts文件夾同一個(gè)目錄(也就是Modules文件夾)下添加一個(gè)aspx頁(yè)或html頁(yè),需要注意的是,如果是在aspx頁(yè)中使用echarts時(shí),需要把要渲染的div放在form標(biāo)簽之外,否則圖形是顯示不出來(lái)的。

3.1.1 在head標(biāo)簽中添加對(duì)echarts的引用如下:

<head runat="server">   <title></title>   <script src="echarts/esljs" type="text/javascript"></script> </head> 

3.1.2 在body標(biāo)記中,form標(biāo)記之外,添加一個(gè)div,用來(lái)做圖表渲染的容器。如下:

<body>  <div id="main"style="height:500px;border:1px solid #ccc;padding:10px;"></div>  ……………  ……………  </body> 

3.1.3 在3.1.3中添加的div標(biāo)記下,添加如下的js代碼段,如下:

 <script type="text/javascript">      //為模塊加載器配置echarts的路徑,這里主要是配置map圖表的路徑,其他的圖表跟map的配置還不太一樣,下邊也會(huì)做另一種類型的圖表事例。 這里引用的主要是echarts文件夾下的echarts-map文件,而其他類型的圖表引用的都是echarts文件夾下的echarts文件。      requireconfig({        paths: {          echarts:'/echarts/echarts',          'echarts/chart/map':'/echarts/echarts-map'        }      });     //動(dòng)態(tài)加載echarts,在回掉函數(shù)中使用,要注意保持按需加載結(jié)構(gòu)定義圖表路徑      require(      [        'echarts',        'echarts/chart/map'      ],      function (ec) {        varmyChart=ecinit(documentgetElementById('main'));        //option主要是圖標(biāo)的一些設(shè)置,這不是這篇文章的重點(diǎn),關(guān)于具體的設(shè)置可以參考官方的文檔說(shuō)明文檔  option= {          title: {            text:'iphone銷¨²量¢?',            subtext:'純ä?屬º?虛¨¦構(gòu)1',            x:'center'          },          tooltip: {            trigger:'item'          },          legend: {            orient:'vertical',            x:'left',            data: ['iphone3','iphone4','iphone5']          },          dataRange: {            min:0,            max:2500,            text: ['高?','低̨ª'],      // 文?本À?,ê?默?認(rèn)¨?為a數(shù)ºy值¦Ì文?本À?            calculable:true,            textStyle: {              color:'orange'            }          },          toolbox: {            show:true,            orient:'vertical',            x:'right',            y:'center',            feature: {              mark:true,              dataView: { readOnly:false },              restore:true,              saveAsImage:true            }          },          series: [      {        name:'iphone3',        type:'map',        mapType:'china',        selectedMode: 'single',        itemStyle: {          normal: { label: { show:true },color:'#ffd700' },// for legend          emphasis: { label: { show:true} }        },        data: [          { name:'北À¡À京?',value:Mathround(Mathrandom() *1000) },          { name:'天¬¨¬津¨°',value:Mathround(Mathrandom() *1000) },          { name:'上¦?海¡ê',value:Mathround(Mathrandom() *1000) },          { name:'重?慶¨¬',value:Mathround(Mathrandom() *1000) },          { name:'河¨®北À¡À',value:Mathround(Mathrandom() *1000) },          { name:'河¨®南?',value:Mathround(Mathrandom() *1000) },          { name:'云?南?',value:Mathround(Mathrandom() *1000) },          { name:'遼¢¨¦寧t',value:Mathround(Mathrandom() *1000) },          { name:'黑¨²龍¢¨²江-',value:Mathround(Mathrandom() *1000) },          { name:'湖t南?',value:Mathround(Mathrandom() *1000) },          { name:'安ã2徽?',value:Mathround(Mathrandom() *1000) },          { name:'山¦?東?',value:Mathround(Mathrandom() *1000) },          { name:'新?疆?',value:Mathround(Mathrandom() *1000) },          { name:'江-蘇?',value:Mathround(Mathrandom() *1000) },          { name:'浙?江-',value:Mathround(Mathrandom() *1000) },          { name:'江-西¡Â',value:Mathround(Mathrandom() *1000) },          { name:'湖t北À¡À',value:Mathround(Mathrandom() *1000) },          { name:'廣?西¡Â',value:Mathround(Mathrandom() *1000) },          { name:'甘¨º肅¨¤',value:Mathround(Mathrandom() *1000) },          { name:'山¦?西¡Â',value:Mathround(Mathrandom() *1000) },          { name:'內(nèi)¨²蒙¨¦古?',value:Mathround(Mathrandom() *1000) },          { name:'陜¦?西¡Â',value:Mathround(Mathrandom() *1000) },          { name:'吉a林¢?',value:Mathround(Mathrandom() *1000) },          { name:'福¡ê建¡§',value:Mathround(Mathrandom() *1000) },          { name:'貴¨®州Y',value:Mathround(Mathrandom() *1000) },          { name:'廣?東?',value:Mathround(Mathrandom() *1000) },          { name:'青¨¤海¡ê',value:Mathround(Mathrandom() *1000) },          { name:'西¡Â藏?',value:Mathround(Mathrandom() *1000) },          { name:'四?川ä¡§',value:Mathround(Mathrandom() *1000) },          { name:'寧t夏?',value:Mathround(Mathrandom() *1000) },          { name:'海¡ê南?',value:Mathround(Mathrandom() *1000) },          { name:'臺(tái)¬¡§灣ª?',value:Mathround(Mathrandom() *1000) },          { name:'香?港?',value:Mathround(Mathrandom() *1000) },          { name:'澳ã?門(mén)?',value:Mathround(Mathrandom() *1000) }        ]      },      {        name:'iphone4',        type:'map',        mapType:'china',        selectedMode: 'single',        itemStyle: {          normal: { label: { show:true },color:'#ff8c00' },// for legend          emphasis: { label: { show:true} }        },        data: [          { name:'北À¡À京?',value:Mathround(Mathrandom() *1000) },          { name:'天¬¨¬津¨°',value:Mathround(Mathrandom() *1000) },          { name:'上¦?海¡ê',value:Mathround(Mathrandom() *1000) },          { name:'重?慶¨¬',value:Mathround(Mathrandom() *1000) },          { name:'河¨®北À¡À',value:Mathround(Mathrandom() *1000) },          { name:'安ã2徽?',value:Mathround(Mathrandom() *1000) },          { name:'新?疆?',value:Mathround(Mathrandom() *1000) },          { name:'浙?江-',value:Mathround(Mathrandom() *1000) },          { name:'江-西¡Â',value:Mathround(Mathrandom() *1000) },          { name:'山¦?西¡Â',value:Mathround(Mathrandom() *1000) },          { name:'內(nèi)¨²蒙¨¦古?',value:Mathround(Mathrandom() *1000) },          { name:'吉a林¢?',value:Mathround(Mathrandom() *1000) },          { name:'福¡ê建¡§',value:Mathround(Mathrandom() *1000) },          { name:'廣?東?',value:Mathround(Mathrandom() *1000) },          { name:'西¡Â藏?',value:Mathround(Mathrandom() *1000) },          { name:'四?川ä¡§',value:Mathround(Mathrandom() *1000) },          { name:'寧t夏?',value:Mathround(Mathrandom() *1000) },          { name:'香?港?',value:Mathround(Mathrandom() *1000) },          { name:'澳ã?門(mén)?',value:Mathround(Mathrandom() *1000) }        ]      },      {        name:'iphone5',        type:'map',        mapType:'china',        selectedMode: 'single',        itemStyle: {          normal: { label: { show:true },color:'#da70d6' },// for legend          emphasis: { label: { show:true} }        },        data: [          { name:'北À¡À京?',value:Mathround(Mathrandom() *1000) },          { name:'天¬¨¬津¨°',value:Mathround(Mathrandom() *1000) },          { name:'上¦?海¡ê',value:Mathround(Mathrandom() *1000) },          { name:'廣?東?',value:Mathround(Mathrandom() *1000) },          { name:'臺(tái)¬¡§灣ª?',value:Mathround(Mathrandom() *1000) },          { name:'香?港?',value:Mathround(Mathrandom() *1000) },          { name:'澳ã?門(mén)?',value:Mathround(Mathrandom() *1000) }        ]      }   ]       };        //以下的這段代碼主要是用來(lái)處理用戶的選擇,應(yīng)用場(chǎng)景是可以做地圖的交互,比如點(diǎn)擊地圖上的某一個(gè)省,獲取相應(yīng)的省的指標(biāo)變化等。        //需要特別注意的是,如果需要點(diǎn)擊某一省作地圖的操作交互的話,還需要為series屬性的每一項(xiàng)添加一個(gè)selectedMode屬性,這里的屬性值為 'single'即單選,也可多選   varecConfig= require('echarts/config');       myCharton(ecConfigEVENTMAP_SELECTED,function (param) {         varselected=paramselected;         varmapSeries=optionseries[0];         vardata= [];         varlegendData= [];         varname;         for (varp=0,len=mapSeriesdatalength; p<len; p++) {           name=mapSeriesdata[p]name;           mapSeriesdata[p]selected=selected[name];           if (selected[name]) {             alert(name); //這里只是簡(jiǎn)單的做一個(gè)事例說(shuō)明,彈出用戶所選的省,如需做其他的擴(kuò)展,可以在這里邊添加相應(yīng)的操作             }         }       });               myChartsetOption(option);     }   );   </script> 

3.1.4  完成以上操作之后,效果如下圖所示:

3.2 LineChart

除了地圖圖表之外的其他的圖標(biāo)的使用方式都差不多。事實(shí)上其他的圖表跟地圖圖表的區(qū)別在于對(duì)配置文件的引用。這里只做一個(gè)折線圖的示例,其它的示例都是一樣的。

3.2.1 跟3.1.1一樣,引入echarts腳本

3.2.2 跟3.2.2一樣,添加渲染圖表的div容器

3.2.3 在3.2.2添加的div下添加如下js代碼塊

<scripttype="text/javascript">      requireconfig({        paths: {          echarts:'/echarts/echarts',          'echarts/chart/bar':'/echarts/echarts',//這里需要注意的是除了mapchart使用的配置文件為echarts-map之外, 其他的圖形引用的配置文件都為echarts,這也是一般的圖形跟地圖的區(qū)別          'echarts/chart/line':'/echarts/echarts'        }      });      require(      [        'echarts',        'echarts/chart/bar',        'echarts/chart/line'      ],      function (ec) {        varmyChart=ecinit(documentgetElementById('main'));        option= {          tooltip: {            trigger:'axis'          },          legend: {            data: ['郵®¨º件t營(yíng)®a銷¨²','聯(lián)¢a盟?廣?告?','視º¨®頻¦Ì廣?告?','直¡À接¨®訪¤?問(wèn)¨º','搜?索¡Â引°y擎?']          },          toolbox: {            show:true,            feature: {              mark:true,              dataView: { readOnly:false },              magicType: ['line','bar'],              restore:true,              saveAsImage:true            }          },          calculable:true,          xAxis: [      {        type:'category',        boundaryGap:false,        data: ['周¨¹一°?','周¨¹二t','周¨¹三¨y','周¨¹四?','周¨¹五?','周¨¹六¢¨´','周¨¹日¨?']      }    ],          yAxis: [      {        type:'value',        splitArea: { show:true }      }    ],          series: [      {        name:'郵®¨º件t營(yíng)®a銷¨²',        type:'line',        stack:'總Á¨¹量¢?',        data: [120,132,101,134,90,230,210]      },      {        name:'聯(lián)¢a盟?廣?告?',        type:'line',        stack:'總Á¨¹量¢?',        data: [220,182,191,234,290,330,310]      },      {        name:'視º¨®頻¦Ì廣?告?',        type:'line',        stack:'總Á¨¹量¢?',        data: [150,232,201,154,190,330,410]      },      {        name:'直¡À接¨®訪¤?問(wèn)¨º',        type:'line',        stack:'總Á¨¹量¢?',        data: [320,332,301,334,390,330,320]      },      {        name:'搜?索¡Â引°y擎?',        type:'line',        stack:'總Á¨¹量¢?',        data: [820,932,901,934,1290,1330,1320]      }    ]        };                     myChartsetOption(option);      }    );    </script>          <divid="main1"style="height:500px;border:1px solid #ccc;padding:10px;"></div>      <scripttype="text/javascript">      requireconfig({        paths: {          echarts:'/echarts/echarts',          'echarts/chart/bar':'/echarts/echarts',          'echarts/chart/line':'/echarts/echarts'        }      });      require(      [        'echarts',        'echarts/chart/bar',        'echarts/chart/line'      ],      function (ec) {        varmyChart=ecinit(documentgetElementById('main1'));        option= {          title: {            text:'未¡ä來(lái)¤¡ä一°?周¨¹氣?溫?變À?化¡¥',            subtext:'純ä?屬º?虛¨¦構(gòu)1'          },          tooltip: {            trigger:'axis'          },          legend: {            data: ['最Á?高?氣?溫?','最Á?低̨ª氣?溫?']          },          toolbox: {            show:true,            feature: {              mark:true,              dataView: { readOnly:false },              magicType: ['line','bar'],              restore:true,              saveAsImage:true            }          },          calculable:true,          xAxis: [      {        type:'category',        boundaryGap:false,        data: ['周¨¹一°?','周¨¹二t','周¨¹三¨y','周¨¹四?','周¨¹五?','周¨¹六¢¨´','周¨¹日¨?']      }    ],          yAxis: [      {        type:'value',        axisLabel: {          formatter:'{value} °?C'        },        splitArea: { show:true }      }    ],          series: [      {        name:'最Á?高?氣?溫?',        type:'line',        itemStyle: {          normal: {            lineStyle: {              shadowColor:'rgba(0,0,0,4)'            }          }        },        data: [11,11,15,13,12,13,10]      },      {        name:'最Á?低̨ª氣?溫?',        type:'line',        itemStyle: {          normal: {            lineStyle: {              shadowColor:'rgba(0,0,0,4)'            }          }        },        data: [-2,1,2,5,3,2,0]      }    ]        };                  myChartsetOption(option);      }    );    </script>          <divid="main2"style="height:500px;border:1px solid #ccc;padding:10px;"></div>      <scripttype="text/javascript">      requireconfig({        paths: {          echarts:'/echarts/echarts',          'echarts/chart/bar':'/echarts/echarts',          'echarts/chart/line':'/echarts/echarts'        }      });      require(      [        'echarts',        'echarts/chart/bar',        'echarts/chart/line'      ],      function (ec) {        varmyChart=ecinit(documentgetElementById('main2'));        option= {          title: {            text:'某3樓£¤盤(pán)¨¬銷¨²售º?情¨¦況?',            subtext:'純ä?屬º?虛¨¦構(gòu)1'          },          tooltip: {            trigger:'axis'          },          legend: {            data: ['意°a向¨°','預(yù)¡è購(gòu)o','成¨¦交?']          },          toolbox: {            show:true,            feature: {              mark:true,              dataView: { readOnly:false },              magicType: ['line','bar'],              restore:true,              saveAsImage:true            }          },          calculable:true,          xAxis: [      {        type:'category',        boundaryGap:false,        data: ['周¨¹一°?','周¨¹二t','周¨¹三¨y','周¨¹四?','周¨¹五?','周¨¹六¢¨´','周¨¹日¨?']      }    ],          yAxis: [      {        type:'value'      }    ],          series: [      {        name:'成¨¦交?',        type:'line',        smooth:true,        itemStyle: { normal: { areaStyle: { type:'default'}} },        data: [10,12,21,54,260,830,710]      },      {        name:'預(yù)¡è購(gòu)o',        type:'line',        smooth:true,        itemStyle: { normal: { areaStyle: { type:'default'}} },        data: [30,182,434,791,390,30,10]      },      {        name:'意°a向¨°',        type:'line',        smooth:true,        itemStyle: { normal: { areaStyle: { type:'default'}} },        data: [1320,1132,601,234,120,90,20]      }    ]        };                  myChartsetOption(option);      }    );    </script> 

3.2.4 完成以上操作之后效果圖如下:

好了,今天就總結(jié)到這里了,希望能給大家?guī)?lái)一些幫助。這里主要是介紹地圖控件的使用,因?yàn)槠涔俜轿臋n上關(guān)于路徑的配置寫(xiě)的很不清楚,所以才會(huì)想把這些走的彎路給總結(jié)一下。對(duì)于其他的圖表控件的使用都很簡(jiǎn)單,大家可以參考官方的文檔。http://echarts.baidu.com/doc/doc.html

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 综艺| 红原县| 高阳县| 乌审旗| 四平市| 安国市| 思茅市| 九台市| 时尚| 清镇市| 英超| 华亭县| 房山区| 石屏县| 木里| 永川市| 夹江县| 龙井市| 齐齐哈尔市| 宜兰市| 南召县| 新龙县| 金溪县| 隆回县| 祁阳县| 柘城县| 三台县| 乌兰县| 孝感市| 乌审旗| 东乡族自治县| 靖安县| 渝中区| 奉贤区| 唐山市| 阿拉尔市| 潮州市| 偃师市| 金塔县| 睢宁县| 云南省|