jquer.svg 插件画函数图像(坐标轴)的例子

2 篇文章 0 订阅

RT  jquery.svg.js的官网 http://keith-wood.name/svg.html(得f a n||长城)

官网就给出了代码 我自己的js学得比较菜吧  整了半天才在自己本地运行出来
现在贴出代码 有需要的拿去

 

 

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>【这里写页面title】</title>
       
        
        <link rel="stylesheet" href="css/jquery.svg.css" type="text/css" media="screen" />


        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/jquery.svg.js"></script>


        <script type="text/javascript" src="js/jquery.svgplot.js"></script>

        <script type="text/javascript">
     
            $(function() { // Shorthand for $(document).ready(function() {
                var plotZooms = [[-2, 2, -1.5, 1.5], [-10, 10, -10, 10]]; 
                var chartAreas = [[0.1, 0.1, 0.95, 0.9], [0.2, 0.1, 0.95, 0.9], 
                    [0.1, 0.1, 0.8, 0.9], [0.1, 0.25, 0.9, 0.9], [0.1, 0.1, 0.9, 0.8]]; 
                var legendAreas = [[0.0, 0.0, 0.0, 0.0], [0.005, 0.1, 0.125, 0.5], 
                    [0.85, 0.1, 0.97, 0.5], [0.2, 0.1, 0.8, 0.2], [0.2, 0.9, 0.8, 0.995]]; 
                $('#svgplot').svg({onLoad: PlotIt});
                
                
                $('#plotit').click(function() { 
        
                    // alert(123)
                    var plotZoom = parseInt($('#plotZoom').val(), 10); 
                    var plotEqual = parseInt($('#plotEqual').val(), 10); 
                    var plotLegend = parseInt($('#plotLegend').val(), 10); 
                    //                    var plotZoom = 0; 
                    //                    var plotEqual = 0; 
                    //                    var plotLegend = 0; 
                    var svg = $('#svgplot').svg('get'); 
                    svg.plot.noDraw(). 
                        legend.show(plotLegend).area(legendAreas[plotLegend]).end(). 
                        xAxis.scale(plotZooms[plotZoom][0], plotZooms[plotZoom][1]).end(). 
                        yAxis.scale(plotZooms[plotZoom][2], plotZooms[plotZoom][3]).end(). 
                        area(chartAreas[plotLegend]).equalXY(plotEqual).redraw(); 
                    
                   // resetSize(svg); 
                }); 
            });
            function PlotIt(svg) {
                //                svg.plot.noDraw().title('Functions', 'blue').
                //                    addFunction('sine', Math.sin, 'blue', 1).format('ivory', 'gray'). 
                //                    gridlines({stroke: 'gray', strokeDashArray: '2,2'}, 'gray').redraw();

                svg.plot.noDraw().title('Functions', 'blue'). 
                    addFunction('Sine', Math.sin, 'blue', 3). 
                    addFunction('Cosine', Math.cos, [-Math.PI, Math.PI], 20, 'red', 3).
                    addFunction('Decaying', decay, 'green', 3). 
                    format('ivory', 'gray'). 
                    gridlines({
                    stroke: 'gray', 
                    strokeDashArray: '4,2'
                }, 'gray').redraw();
                svg.plot.xAxis.scale(-0.5, 12).ticks(1, 0.1); 
                svg.plot.yAxis.scale(-0.5, 12).ticks(1, 0.1); 
                svg.plot.legend.settings({
                    fill: 'lightgoldenrodyellow', 
                    stroke: 'gray'
                }); 
                svg.plot.status(showPlotStatus); 
            }
            function decay(x) { 
                return Math.exp(-0.4 * x) * Math.sin(x); 
            } 
 
            function showPlotStatus(label) { 
                $('#svgplot').attr('title', label); 
            }
        </script>
    </head>
    <body>            
        <%@include file="nav.jsp" %>   
        <div class="container margintop40" >
            <div id="plot" class="" style="min-width: 0px; ">
                <p>Zoom <select id="plotZoom">
                        <option value="0">small</option>
                        <option value="1">large</option>
                    </select>
                    with <select id="plotEqual">
                        <option value="0">unequal</option>
                        <option value="1" selected="selected">equal</option>
                    </select> x/y units
                    and <select id="plotLegend">
                        <option value="0">no</option>
                        <option value="1">left</option>
                        <option value="2">right</option>
                        <option value="3">top</option>
                        <option value="4">bottom</option>
                    </select> legend&nbsp;&nbsp;
                    <input type="button" id="plotit" class="btn" value="Plot it" />
                    <input type="button" id="test" class="btn" value="test" />
                </p>
                <div id="svgplot" style="width: 100%; height: 400px;" title="">
                  
                </div>


            </div>


        </div>
  
    </body>
</html>
 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值