echarts 應用數個例子,echarts數個例子

來源:互聯網
上載者:User

echarts 應用數個例子,echarts數個例子

  • 應用一:環形圖和餅圖嵌套

先說明一下內部檔案分布:

注意輸入數組的格式(不是一般Javascript 的數組格式,而是有點像json 的樣子),代碼如下:

profiles_pie_weibo:function(event_id){heats=[{name:'直達', value:335},{name:'營銷廣告', value:679},{name:'搜尋引擎', value:1548}];heats2 = [{name:'直達', value:335},{name:'郵件營銷', value:310},{name:'聯盟廣告', value:234},{name:'視頻廣告', value:135},{name:'百度', value:1048},{name:'Google', value:251},{name:'必應', value:147},{name:'Google', value:102}];        // echarts庫檔案路徑配置        require.config({            paths: {                echarts: $base.appConfig.lib_scripts_path + '/echarts/'            }        });                // 使用圖表        require(            [                'echarts',                'echarts/chart/pie'            ],            function (ec) {                // 基於準備好的dom,初始化echarts圖表                var myChart = ec.init(document.getElementById('profiles_layout'));        var option = {tooltip : {//滑鼠hover時提示    trigger: 'item',    formatter: "{a} <br/>{b} : {c} ({d}%)"},series: [    {     name: '訪問來源',     type:'pie',     radius: [0,'35%'],//內部餅圖     itemStyle : {          normal : {              label : {                  position : 'inner'              },              labelLine : {                  show : false              }          }     },     data:  heats    },    {     name: '訪問來源2',     type:'pie',     radius: ['50%','70%'],//數組形式,環形圖     data:  heats2    }]        };                // 為echarts對象載入資料     myChart.setOption(option);            }        );//======end require=======},

出來的:



  • 應用二:SVG擴充-人體圖(人物畫像/使用者畫像的簡化版)

這個東西代碼不難,但那個SVG底圖的對應代碼起著關鍵的影響,所以搞這個之前最好學一點SVG代碼編寫規則。好吧,做echarts SVG擴充的人還是比較少的,網上幾乎找不到多少直接相關資料,只能自己摸弄著過河了~

代碼(有一點點無用代碼,不影響閱讀):

//人物畫像profiles_weibo_3:function(event_id){// echarts庫檔案路徑配置        require.config({            paths: {                echarts: $base.appConfig.lib_scripts_path + '/echarts/'            }        });        // 使用圖表        require(            [                'echarts',                'echarts/chart/map'            ],        function (ec) {            // 基於準備好的dom,初始化echarts圖表            var myChart = ec.init(document.getElementById('profiles_layout'));                         // 自訂擴充圖表類型:mapType = body        require('echarts/util/mapData/params').params.bodyMale = {            getGeoJson: function (callback) {                $.ajax({                    url: $base.appConfig.lib_scripts_path + "/echarts/svg/raw_man.svg",                    dataType: 'xml',                    success: function(xml) {                        callback(xml);                    },                error:function(XMLResponse){                alert(XMLResponse.responseText);                }                });            }        };var option = {title : {        text : '人體密碼',        subtext: '地圖SVG擴充',        x:'center'    },    tooltip : {        trigger: 'item'    },    dataRange: {        min: 0,        max: 100,        x: 'center',        y: 'center',        calculable : true,        itemHeight:30,        color: ['orangered','yellow','lightskyblue']    },    series : [              {                  name: '人體密碼-男',                  type: 'map',                  mapType: 'bodyMale', // 自訂擴充圖表類型                  mapLocation: {                      x:'left'                  },                  roam:true,                  itemStyle:{                      normal:{label:{show:true}},                      emphasis:{label:{show:true}}                  },                  data:[                      {name: 'head', value: 90},                      {name: 'body', value: 60},                      {name: 'left_hand', value: 70},                      {name: 'right_hand', value: 50},                      {name: 'left_leg', value: 40},                      {name: 'right_leg', value: 30},                      {name: 'bag', value: 90}                  ],                  markLine : {                      smooth:true,                      effect : {                          show: true,                          scaleSize: 1,                          period: 30,                          color: '#fff',                          shadowBlur: 5                      },                      data : [                          [                              {name:'男',geoCoord:[138, 126]},                               {name:'女',value:90,geoCoord:[268, 56]}                          ]                      ]                  }              }              ]//======end series=======};myChart.setOption(option);            }        );//======end require=======},

:



SVG Reference:

echarts sample:http://echarts.baidu.com/doc/example/map16.html?qq-pf-to=pcqq.c2c

echarts sample 中用到的SVG檔案:https://code.csdn.net/u013476464/baidu_data_visualization/tree/master/doc/example/svg/body-male.svg

SVG擴充其他例子:http://www.oschina.net/code/piece_full?code=38878

SVG線上編輯:http://editor.method.ac/

SVG 學習:http://www.w3cplus.com/html5/svg-transformations.html,http://www.tuicool.com/articles/yUZz2mu


上面的例子用到我做的SVG檔案。只是圖片編輯工具是不夠的,還需要修改裡面的代碼。另外,stroke 和fill 是不能加在需要作色彩變化的項上的,不然dataRange中的著色會不成功。代碼如下:

<?xml version="1.0"?><svg width="232" height="336" xmlns="http://www.w3.org/2000/svg"> <!-- Created with Method Draw - http://github.com/duopixel/Method-Draw/ --> <g>  <title>background</title>  <rect fill="#fff" id="canvas_background" height="338" width="234" y="-1" x="-1"/>  <g display="none" overflow="visible" y="0" x="0" height="100%" width="100%" id="canvasGrid">   <!-- <rect fill="url(#gridpattern)" stroke-width="0" y="0" x="0" height="100%" width="100%"/>-->  </g> </g> <g>  <title>Layer 1</title>  <ellipse name="head" ry="39.5" rx="39" id="svg_1" cy="51" cx="116.5" stroke-width="1.5"/>  <ellipse name="body" ry="66" rx="15" id="svg_2" cy="158.5" cx="116.5" stroke-width="1.5"/>  <ellipse name="right_leg" ry="37.5" rx="10" id="svg_3" cy="268" cx="95.5" stroke-width="1.5"/>  <ellipse name="left_leg" ry="48" rx="9.5" id="svg_4" cy="270.5" cx="144" stroke-width="1.5"/>  <ellipse name="right_hand" ry="8.5" rx="41.5" id="svg_5" cy="144" cx="53" stroke-width="1.5"/>  <ellipse name="left_hand" ry="9" rx="40.5" id="svg_6" cy="142.5" cx="187" stroke-width="1.5"/>  <path id="svg_8" d="m91.5,43.5c12,2 18,-3 18,-3c0,0 -30,1 -18,3z" fill-opacity="null" stroke-opacity="null" stroke-width="1.5" stroke="#000" fill="#fff"/>  <path id="svg_9" d="m127.5,39.5c15,4 15,3 14.5,2.5c0.5,0.5 -29.5,-6.5 -14.5,-2.5z" fill-opacity="null" stroke-opacity="null" stroke-width="1.5" stroke="#000" fill="#fff"/>  <path id="svg_10" d="m99.5,68.5c0,-1 15,11 14.5,10.5c0.5,0.5 18.5,-9.5 18,-10" fill-opacity="null" stroke-opacity="null" stroke-width="1.5" stroke="#000" fill="#fff"/>  <path id="svg_11" name="bag" d="m22.5,161.5c-10,17 -11,61 -11.5,60.5c0.5,0.5 14.5,28.5 14,28c0.5,0.5 13.5,-25.5 13,-26l-15.5,-62.5z"/> </g></svg>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.