Speed up development with full-stack environments for every branch.

Learn More

How to use Flot to make a simple Graph with jQuery

Forked from How to use the jQuery UI Slider.

1614 Runs 3378 Views 837 Copies
Saved

Saved

pg1 45

pg1
published 4 years ago

<!doctype html>
<html>
<head>

    <title>How to use Flot to make a simple Graph with jQuery</title>
    
    <style>
        body{
            text-align: center;
            font-family: arial;
        }
   
        #graph{
            width:600px;
            height: 400px;
        }
        
    </style>


</head>
<body>
    
    <div id="graph"></div>

    <!-- add jquery and flot plugin -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="./jquery.flot.js"></script>

    <script>

        //When DOM loaded we run the flot plugin
        $(document).ready(function() {

            //generate data points for the graph
            //d1 and d2 is js array which stores the data
            var d1 = [];
            for (var i = 0; i < 14; i += 0.1) {
                d1.push([i, Math.sin(i)]);
            }

            var d2 = [];
            for (var i = 0; i < 14; i += 0.1) {
                d2.push([i, Math.cos(i)]);
            }

            //we call the plot function which creates the graph 
            $.plot("#graph", [ d1, d2 ]);
            
        });

    </script>

</body>
</html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).