flot 自定义显示日期

html 代码:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
  2. <html>  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.     <title>Flot Examples: Time Axes</title>  
  6.     <link href="../examples.css" rel="stylesheet" type="text/css">  
  7.     <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->  
  8.     <script language="javascript" type="text/javascript" src="../../jquery.js"></script>  
  9.     <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script>  
  10.     <script language="javascript" type="text/javascript" src="../../jquery.flot.time.js"></script>  
  11.     <script type="text/javascript">  
  12.         Date.prototype.Format = function (fmt) { //author: meizz  
  13.             var o = {  
  14.                 "M+": this.getMonth() + 1, //月份  
  15.                 "d+": this.getDate(), //日  
  16.                 "h+": this.getHours(), //小时  
  17.                 "m+": this.getMinutes(), //分  
  18.                 "s+": this.getSeconds(), //秒  
  19.                 "q+": Math.floor((this.getMonth() + 3) / 3), //季度  
  20.                 "S": this.getMilliseconds() //毫秒  
  21.             };  
  22.             if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
  23.             for (var k in o)  
  24.                 if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
  25.             return fmt;  
  26.         };  
  27.   
  28.         var currentDate = new Date();  
  29.         var arr = [  
  30.             [1,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-7).Format("yyyy-MM-dd")],  
  31.             [2,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-6).Format("yyyy-MM-dd")],  
  32.             [3,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-5).Format("yyyy-MM-dd")],  
  33.             [4,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-4).Format("yyyy-MM-dd")],  
  34.             [5,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-4).Format("yyyy-MM-dd")],  
  35.             [6,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-3).Format("yyyy-MM-dd")],  
  36.             [7,new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()-1).Format("yyyy-MM-dd")]  
  37.         ];  
  38.   
  39.     $(function() {  
  40.   
  41.     var d = [  
  42.             [1,1],  
  43.             [2,3],  
  44.             [3,4],  
  45.             [4,8],  
  46.             [5,10],  
  47.             [6,4],  
  48.             [7,4]  
  49.         ];  
  50.   
  51.         $.plot("#placeholder", [d], {  
  52.                 xaxis: {  
  53.                                     ticks:arr  
  54.                 },  
  55.                 series: {  
  56.                     lines: { show: true},  
  57.                     points: { show: true }  
  58.                 }  
  59.             });  
  60.   
  61.     });  
  62.   
  63.   
  64.   
  65.     </script>  
  66. </head>  
  67. <body>  
  68.   
  69.     <div id="content">  
  70.   
  71.         <div class="demo-container">  
  72.             <div id="placeholder" class="demo-placeholder"></div>  
  73.         </div>  
  74.   
  75.     </div>  
  76.   
  77.   
  78. </body>  
  79. </html>  

显示效果:




原理:要展示的数据的 x 坐标和自定义的 x 坐标里面的第一个值相同,后面的值就是自定义要显示的内容。

原文:http://blog.csdn.net/tengdazhang770960436/article/details/38872269

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值