毕业设计代码记录

最近开始搞毕业论文了,亚历山大,记录一点毕业设计需要用的代码

<html>  
  <head>  
        <meta charset="utf-8">  
        <title>颜色插值</title>  
  </head> 
  <style>

  </style>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>

var width = 400,
    height = 400;
    
var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

var a = d3.rgb(255,0,0);    //红色
var b = d3.rgb(0,255,0);    //绿色
 
var compute = d3.interpolate(a,b);

var linear = d3.scale.linear()
                .domain([0,150])
                .range([0,1]);

var rects = svg.selectAll("rect")
                .data(d3.range(150))
                .enter()
                .append("rect")
                .attr("x",function(d,i){
                    return i%15 * 15;
                })
                .attr("y",function(d,i){
                    return Math.floor(i/15) * 15;
                })
                .attr("width",15)
                .attr("height",15)
                .style("fill",function(d){
                    return compute(linear(d));
                })
                .on("mouseover",function(d){
                    d3.select(this)
                        .style("fill","yellow");
                })
                .on("mouseout",function(d){
                    d3.select(this)
                        .style("fill",compute(linear(d)).toString());
                });


//定义一个线性渐变
var defs = svg.append("defs");

var linearGradient = defs.append("linearGradient")
                        .attr("id","linearColor")
                        .attr("x1","0%")
                        .attr("y1","0%")
                        .attr("x2","100%")
                        .attr("y2","0%");

var stop1 = linearGradient.append("stop")
                .attr("offset","0%")
                .style("stop-color",a.toString());

var stop2 = linearGradient.append("stop")
                .attr("offset","100%")
                .style("stop-color",b.toString());

//添加一个矩形,并应用线性渐变
var colorRect = svg.append("rect")
                .attr("x", 15)
                .attr("y", 200)
                .attr("width", 200)
                .attr("height", 30)
                .style("fill","url(#" + linearGradient.attr("id") + ")")
                .on("mouseover",function(d){
                    d3.select(this)
                        .style("fill","yellow");
                })
                .on("mouseout",function(d){
                    d3.select(this)
                        .style("fill","url(#" + linearGradient.attr("id") + ")");
                });



</script>
        
    </body>  
</html>

wKiom1ZXCeeAmhg4AAASPARBUvA394.jpg

转自:http://www.ourd3js.com/wordpress/?p=1111



spacer.gifhttp://www.hcharts.cn/demo/highmaps.php
spacer.gifhttp://d3js.org/
spacer.gifhttp://www.ourd3js.com/wordpress/?p=1111
spacer.gifhttp://blog.csdn.net/kalision/article/details/40503393

wKiom1ZbrAfSwOkEAACJYSQV_BA893.jpg





























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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值