一、morris.js
优点:轻巧、简单好用
缺点:没highcharts功能多,常用的足以
网址:http://morrisjs.github.io/morris.js/
核心代码
1、head调用js
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="/js/jquery-1.4.4.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
2、添加元素
<div id="myfirstchart" style="height:250px;"></div>
3、js代码
<script type="text/javascript" language="javascript">new Morris.Line({ element: 'myfirstchart', data: [ { day: "2016-07-10", value: 120 }, { day: "2016-07-11", value: 10 }, { day: "2016-07-12", value: 5 }, { day: "2016-07-13", value: 50 }, { day: "2016-07-14", value: 20 } ], // The name of the data record attribute that contains x-values. xkey: 'day', // A list of names of data record attributes that contain y-values. ykeys: ['value'], // Labels for the ykeys -- will be displayed when you hover over the // chart. labels: ['阅读量'], parseTime:false //注意 }); </script>
ajax例子:
function yizhou() { if($("#myfirstchart").text()=="") { $.post("newsCountAjax.aspx",{type:0},function(datas){ var dataObj=eval("("+datas+")");//转换为json对象 //1周 new Morris.Line({ element: 'myfirstchart', data: dataObj, xkey: 'day', ykeys: ['value'], labels: ['阅读量'], parseTime:false }); }); } }
yizhou();
参数说明:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
未公開的參數選項說明:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
二、highcharts
优点:功能多,强大
缺点:功能太多,有版权等
网址:http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/line-basic/