jquery flot 在节点上显示提示

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
    <title>Flot Examples: Basic Usage</title>  
    <link href="../examples.css" rel="stylesheet" type="text/css">  
    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->  
    <script language="javascript" type="text/javascript" src="../../jquery.js"></script>  
    <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script>  
  
    <!-- 需要引用下面的两个 js 库文件用来显示提示和弹出框 -->  
  
    <script type="text/javascript">  
        var options = {  
            lines: {  
                show: true  
            },  
            points: {  
                show: true  
            },  
            xaxis: {  
                tickDecimals: 0,  
                tickSize: 1  
            },  
            grid: { hoverable: true}// 开启 hoverable 事件  
        };  
  
    $(function() {  
  
        var d1 = [];  
        for (var i = 0; i < 14; i += 0.5) {  
            d1.push([i, Math.sin(i)]);  
        }  
  
        var d2 = { "label": "Europe (EU27)","data":[[0, 3], [4, 8], [8, 5], [9, 13]]};  
  
        // A null signifies separate line segments  
        var d3 = [[0, 12], [7, 12], [7, 2.5], [12, 2.5]];  
  
        // 为图添加数据  
        $.plot("#placeholder", [ d1,d2, d3 ],options);  
  
        // 节点提示  
        function showTooltip(x, y, contents) {  
            $('<div id="tooltip">' + contents + '</div>').css( {  
                position: 'absolute',  
                display: 'none',  
                top: y + 10,  
                left: x + 10,  
                border: '1px solid #fdd',  
                padding: '2px',  
                'background-color': '#dfeffc',  
                opacity: 0.80  
            }).appendTo("body").fadeIn(200);  
        }  
  
        var previousPoint = null;  
        // 绑定提示事件  
        $("#placeholder").bind("plothover", function (event, pos, item) {  
            if (item) {  
                if (previousPoint != item.dataIndex) {  
                    previousPoint = item.dataIndex;  
                    $("#tooltip").remove();  
                    var y = item.datapoint[1].toFixed(0);  
  
                    var tip = "展现量:";  
                    showTooltip(item.pageX, item.pageY,tip+y);  
                }  
            }  
            else {  
                $("#tooltip").remove();  
                previousPoint = null;  
            }  
        });  
    });  
  
  
  
    </script>  
</head>  
<body>  
  
    <div id="header">  
        <h2>Basic Usage</h2>  
    </div>  
  
    <div id="content">  
  
        <div class="demo-container">  
            <div id="placeholder" class="demo-placeholder"></div>  
        </div>  
  
        <p>You don't have to do much to get an attractive plot.  Create a placeholder, make sure it has dimensions (so Flot knows at what size to draw the plot), then call the plot function with your data.</p>  
  
        <p>The axes are automatically scaled.</p>  
  
    </div>  
  
    <div id="footer">  
        Copyright &copy; 2007 - 2014 IOLA and Ole Laursen  
    </div>  
  
</body>  
</html> 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值