一个简单的折线图demo:

1.建立容器

 

 
  
  1. <div id="demo1">  
  2.   
  3. </div> 

 

2.KISSY包配置:

 

 
  
  1. //包配置  
  2. KISSY.config({ 
  3.  combine:true, 
  4.   packages:[ 
  5.       { 
  6.         name:"gallery", 
  7.         path:"http://a.tbcdn.cn/s/kissy/", 
  8.         charset:"utf-8" 
  9.       } 
  10.     ] 
  11. }); 

 

关于kissy可以参考 官方网站 :http://docs.kissyui.com/

3.引入linechart js文件

 
  
  1. KISSY.use("gallery/kcharts/1.1/linechart/index",function(S,LineChart){ 
  2. //TODO 

4.构造Linechart实例

 
  
  1. var linechart = new LineChart({ 
  2.      renderTo:"#demo1", 
  3.      points:{ 
  4.        attr:{ 
  5.          type:"auto" 
  6.        } 
  7.      }, 
  8.      yLabels:{ 
  9.        css:{ 
  10.          "marginLeft":"-4px", 
  11.          "font-family":"Microsoft Yahei", 
  12.          "font-size":"10px" 
  13.        } 
  14.      }, 
  15.      xLabels:{ 
  16.        css:{ 
  17.          "font-family":"Microsoft Yahei", 
  18.           "font-size":"10px" 
  19.        } 
  20.      }, 
  21.      title:{ 
  22.              content:"Monthly Average Temperature", 
  23.              css:{ 
  24.              } 
  25.            }, 
  26.            anim:{}, 
  27.            subTitle:{ 
  28.              content:"Source: WorldClimate.com", 
  29.              css:{ 
  30.  
  31.              } 
  32.            }, 
  33.            lineType:"arc", 
  34.       xAxis: { 
  35.          text:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
  36.                    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
  37.            }, 
  38.            yAxis:{ 
  39.              num:7 
  40.            }, 
  41.      series:[{ 
  42.                text: 'Tokyo', 
  43.                data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] 
  44.            }, { 
  45.                text: 'New York', 
  46.                data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] 
  47.            } 
  48.            , { 
  49.                text: 'Berlin', 
  50.                data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] 
  51.            }, { 
  52.                text: 'London', 
  53.                data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] 
  54.            } 
  55.            ], 
  56.      defineKey:{ 
  57.        x:"week", 
  58.        y:"y" 
  59.      }, 
  60.      legend:{ 
  61.        isShow:true, 
  62.        css:{ 
  63.          marginLeft:250, 
  64.          marginTop:260 
  65.        } 
  66.      }, 
  67.      tip:{ 
  68.        offset:{ 
  69.                    x:10, 
  70.                    y:10 
  71.                }, 
  72.        template:function(){ 
  73.          return "<span style='font-size:10px'>"+arguments['0']['text'] + "</span><br/>" + arguments['0']['y'] + "\u2103"; 
  74.        } 
  75.      } 
  76.  }); 

 

 

整体代码如下:(复制到html文件运行即可)

 
  
  1. <!doctype html> 
  2. <html> 
  3. <head> 
  4.   <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  5. <link rel="stylesheet" href="http://a.tbcdn.cn/p/global/1.0/global-min.css" /> 
  6. <style> 
  7. #demo1{ 
  8.     width:750px; 
  9.     height:300px; 
  10.     margin:0px auto; 
  11. #demo1 .ks-charts-legend ul li{ 
  12.   float: left;   
  13.   padding: 10px; 
  14. #demo1 .ks-charts-legend .disable{ 
  15.   color:#ccc; 
  16. #demo1 .ks-charts-legend .legend-text{ 
  17.   padding-left: 5px; 
  18. </style> 
  19. </head> 
  20. <body> 
  21. <div id="demo1"> 
  22.  
  23. </div> 
  24. <script src="http://a.tbcdn.cn/s/kissy/1.3.0/kissy-min.js"></script> 
  25. <script type="text/javascript"> 
  26. // KISSY.Config.debug = true
  27. //包配置  
  28. KISSY.config({ 
  29.  combine:true, 
  30.   packages:[ 
  31.       { 
  32.         name:"gallery", 
  33.         path:"http://a.tbcdn.cn/s/kissy/", 
  34.         charset:"utf-8" 
  35.       } 
  36.     ] 
  37. }); 
  38.  
  39. KISSY.use("gallery/kcharts/1.1/linechart/index",function(S,LineChart){ 
  40.   var linechart = new LineChart({ 
  41.       renderTo:"#demo1", 
  42.       points:{ 
  43.         attr:{ 
  44.           type:"auto" 
  45.         } 
  46.       }, 
  47.       yLabels:{ 
  48.         css:{ 
  49.           "marginLeft":"-4px", 
  50.           "font-family":"Microsoft Yahei", 
  51.           "font-size":"10px" 
  52.         } 
  53.       }, 
  54.       xLabels:{ 
  55.         css:{ 
  56.           "font-family":"Microsoft Yahei", 
  57.            "font-size":"10px" 
  58.         } 
  59.       }, 
  60.       title:{ 
  61.               content:"Monthly Average Temperature", 
  62.               css:{ 
  63.               } 
  64.             }, 
  65.             anim:{}, 
  66.             subTitle:{ 
  67.               content:"Source: WorldClimate.com", 
  68.               css:{ 
  69.  
  70.               } 
  71.             }, 
  72.             lineType:"arc", 
  73.        xAxis: { 
  74.           text:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
  75.                     'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
  76.             }, 
  77.             yAxis:{ 
  78.               num:7 
  79.             }, 
  80.       series:[{ 
  81.                 text: 'Tokyo', 
  82.                 data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] 
  83.             }, { 
  84.                 text: 'New York', 
  85.                 data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] 
  86.             } 
  87.             , { 
  88.                 text: 'Berlin', 
  89.                 data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] 
  90.             }, { 
  91.                 text: 'London', 
  92.                 data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] 
  93.             } 
  94.             ], 
  95.       defineKey:{ 
  96.         x:"week", 
  97.         y:"y" 
  98.       }, 
  99.       legend:{ 
  100.         isShow:true, 
  101.         css:{ 
  102.           marginLeft:250, 
  103.           marginTop:260 
  104.         } 
  105.       }, 
  106.       tip:{ 
  107.         offset:{ 
  108.                     x:10, 
  109.                     y:10 
  110.                 }, 
  111.         template:function(){ 
  112.           return "<span style='font-size:10px'>"+arguments['0']['text'] + "</span><br/>" + arguments['0']['y'] + "\u2103"; 
  113.         } 
  114.       } 
  115.   }); 
  116.  
  117. });</script> 
  118. </body> 
  119. </html>