goodman原生js实现自定义雷达图效果代码

代码语言:html

所属分类:图表

代码描述:goodman原生js实现自定义雷达图效果代码

代码标签: 实现 自定义 雷达图 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
   
<meta charset="utf-8" />
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
   
<title>demo</title>
   
<meta name="viewport" content="width=device-width, initial-scale=1">
   
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
   
<meta name="apple-mobile-web-app-capable" content="yes">
   
<meta name="apple-mobile-web-app-status-bar-style" content="black">
   
<meta name="format-detection" content="telephone=no">
<style>
    body
{
   
background-color: #292929;
}

.tab{
   
margin-top: 50px;
   
background-color: #fff;
   
font-size: 15px;
   
margin-left: 50%;
   
transform: translateX(-50%);
   
display: inline-block;
   
box-sizing: border-box;
}
.tab_header{
   
position: relative;
   
background: url('//repo.bfw.wiki/bfwrepo/image/5e5ef0b278727.png');
   
background-size:cover;
}
.tab_header a{
   
width: 64px;
   
height: 64px;
   
position: absolute;;
   
left: 50%;
   
top: 50%;
   
margin-left: -32px;;
   
margin-top: -30px;
   
display: block;
   
z-index: 1;
   
background-size: 100%;
}
.tab_header>a>img{
   
width: 100%;
   
height: 100%;
   
display: block;
}
.tab_main{
   
padding: 5px 10px;
   
box-sizing: border-box;
}

.tab_main>p{
   
color: #848484;
   
box-sizing: border-box;

}
#controlBar{
   
}
#myCanvas{
   
margin: 0 auto;
}
input
{
   
width: 100px;
   
border: none;
   
background-color: #eee;;
   
padding: 5px;
}
#controlBar label{
   
margin: 0 10px;
}
#controlBar div{
   
padding: 5px;
}
.tab_main button{
   
width: 100%;
   
margin: 10px 0;
}
</style>
</head>
<body>
   
<div class="tab">
       
<div class="tab_header">
           
<canvas id="myCanvas"></canvas>
       
</div>
   
       
<div class="tab_main">
           
<h3>修改值来查看实时效果:</h3>
           
<div id="controlBar"></div>
           
<button id="load">加载</button>
       
</div>
   
</div>

   
   
<script >
        (function(){


    class Radar{
        fontSyle="12px Arial";
        speed = 2;
        startVal = 0;
        maxValue = 80;
        textColor = "rgba(255,255,255,1)";
        background={
            rect:[
               {
                    color:"rgba(56,60,63,0.4)",
                    size:80,
               },
               {
                    color:"rgba(115,115,116,0.3)",
                    size:75,
               },
           
            ],
            circle:[
                {
                    color:"rgba(66,139,234,0.1)",
                    size:4
                },
                {
                    color:"rgba(66,139,234,1)",
                    size:2
                }
               
            ]
        }
        customizeBackground = (data)=>{
            this.background = data;
        }

        setFontStyle = (fontSyle)=>{
            this.fontSyle = fontSyle.style;
            this.textColor = fontSyle.color;
        }

        setContextSize = (width,height)=>{
       
            this.el.width=width;
            this.el.height=height;//设置好canvas的宽高
            this.c= {x:width/2,y:height/2};
        }

        setIndex = (index)=>{

            this.index = index;

        }

        getIndex = function(){
            return this.index;
        }

        constructor(options){
            this.index = options.data;
            this.el = document.querySelector(options.el);
            this.ctx = this.el.getContext("2d");
            this.maxValue = options.size;
        }

    };

    Radar.prototype.solveEquations=function(tan,isRight,val){  //解出x位置
        var sec2=Math.pow(tan,2)+1;

        var b2 = 4*Math.pow(sec2,2)*Math.pow(this.c.x,2) ;
        var ac4 = 4*sec2*(sec2*Math.pow(this.c.x,2)-Math.pow(val,2))
        var delta =b2 - ac4;

   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0