示例描述

该示例展示图例设置,包括图例位置、图例标题、图例中每一项的子标题。

效果演示

示例代码

<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script src='http://dev.dituhui.com/sdk/1.0.0/js/dituhui-flash.js'></script>
  <script src='http://dev.dituhui.com/sdk/1.0.0/js/sample-data.js'></script>
  <script type="text/javascript">
   var map = null;
   function init(){
    map = new Dituhui.Map("myMap", "http://dev.dituhui.com/sdk/1.0.0/swfs/", "100000", Dituhui.MapType.RANGE, "setData", "onError");
   }
   /*将数据分为4组,为每一组的图例设置标签内容*/
   function setData()
   {
    var mapStyles = [
     {min:1,max:10,displayValue:'10%以下'},
     {min:10,max:11,displayValue:'10%-11%'},
     {min:11,max:12,displayValue:'11%-12%'},
     {min:12,max:14,displayValue:'12%以上'}];

    var option = 
    {
     data: data, 
     styles:mapStyles, 
     fillColorType:"black", 
     valueField:'gdprate',
     /*图例标题*/
     legendTitle:"2012GDP增速",
     /*图例位置,包括:"left_top"(左上),"left_bottom"(左下),
     "right_top"(右上),"right_bottom"(右下)四种,默认为left_top*/
     legendPosition:"left_bottom",
     backgroundColor:"#F5F5F5"
    };
    map.setMapOptions(option);
   }
   function onError(errorcode)
   {
    /*errorcode:错误编码,有关错误编码的详细描述可参考:
    "开发指南"-->"API参考"-->"错误编码"*/
    alert(errorcode);          
   }
   window.onload = init;
  </script>
 </head>
 <body>
  <div id='myMap' style='width:680px;height:500px'>
  </div>
 </body>
</html>