<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>仪表盘</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
</head>
<style type="text/css">
body{margin:20px auto; padding:0; width:800px; }
/*canvas{border:dashed 2px #CCC}*/
</style>
<script type="text/javascript">
var canid;
function $$(id){
return document.getElementById(id);
}
function pageLoad(){
var can = $$(canid);
var cans = can.getContext('2d');
cans.beginPath();
cans.arc(400,300,180,-10,0,false);
//cans.closePath();
cans.strokeStyle = 'red';
cans.fillStyle = "blue";
cans.lineWidth = 30;
cans.stroke(); cans.beginPath();
cans.arc(400,300,90,0,4/3*Math.PI,true);
//cans.closePath();
cans.strokeStyle = 'red';
cans.fillStyle = "blue";
cans.lineWidth = 10;
cans.fill(); //cans.beginPath();
//cans.arc(400,300,90,0,Math.PI,2);
//cans.closePath();
//cans.strokeStyle = 'blue';
//cans.lineWidth = 80;
//cans.stroke();
} function pageLoad2(a,b,c,d,e,f,g){
var can = $$(canid);
var cans = can.getContext('2d');
cans.beginPath();
cans.arc(a,b,c,d,e,f);
cans.strokeStyle = g;
cans.fillStyle = g;
cans.lineWidth = 30;
cans.stroke(); cans.font = "bold 30px Arial";
cans.fillStyle = g;
} function Drawarc(yuanxinx,yuanxiny, banjing, value, dengfen){
var can = $$(canid);
var cans = can.getContext('2d');
cans.beginPath();
cans.arc(yuanxinx,yuanxiny,banjing,(Math.PI*2)*(180/360),(Math.PI*2)*(((180/dengfen)*value+178)/360),false);
var yanse;
if (value<=7)
yanse = '#81d135';
if (value>7 && value<=14)
yanse = '#fdc159';
if (value>14)
yanse = '#fb6376';
cans.strokeStyle = yanse;
cans.fillStyle = yanse;
cans.lineWidth = 2;
cans.stroke(); cans.font = "bold 30px Arial";
cans.fillStyle = yanse;
} function Square(x)
{
return x*x;
} function DrawLine(x1,y1,x2,y2)
{
var can = $$(canid);
var cans = can.getContext('2d');
cans.strokeStyle='#000';
cans.lineWidth=1;
//cans.lineCap='square';
cans.beginPath();
cans.moveTo(x1,y1);
cans.lineTo(x2,y2);
cans.stroke();
//cans.closePath();
} function Drawarc1(yuanxinx,yuanxiny, banjing, value, dengfen){
var can = $$(canid);
var cans = can.getContext('2d');
cans.beginPath();
var jiaodu = 180 - (180/dengfen)*value;
var jiaodu1 = jiaodu-1.8;
var jiaodu2 = jiaodu+1.8;
var x1 = yuanxinx + banjing * Math.cos((jiaodu * 3.14)/180.0);
var y1 = yuanxiny - banjing * Math.sin((jiaodu * 3.14)/180.0); var jiaodian1x = yuanxinx + banjing * Math.cos((jiaodu1 * 3.14)/180.0);
var jiaodian1y = yuanxiny - banjing *Math.sin((jiaodu1 * 3.14)/180.0);
var jiaodian2x = yuanxinx + banjing * Math.cos((jiaodu2 * 3.14)/180.0);
var jiaodian2y = yuanxiny - banjing *Math.sin((jiaodu2 * 3.14)/180.0); //缩短短半径
//alert(x1 +','+ y1);
var sdbanjing = banjing -20;
var jiaodian3x = yuanxinx + sdbanjing *Math.cos((jiaodu * 3.14)/180.0);
var jiaodian3y = yuanxiny - sdbanjing *Math.sin((jiaodu * 3.14)/180.0); var jcbanjing = banjing +6;
var jiaodian4x = yuanxinx + jcbanjing *Math.cos((jiaodu * 3.14)/180.0);
var jiaodian4y = yuanxiny - jcbanjing *Math.sin((jiaodu * 3.14)/180.0); //alert(jiaodian3x +','+ jiaodian3y); DrawLine(jiaodian1x,jiaodian1y, jiaodian3x, jiaodian3y);
DrawLine(jiaodian2x,jiaodian2y, jiaodian3x, jiaodian3y); //DrawLine(jiaodian1x,jiaodian1y, jiaodian4x, jiaodian4y);
//DrawLine(jiaodian2x,jiaodian2y, jiaodian4x, jiaodian4y); cans.arc(x1,y1,4,0,Math.PI*2,false);
var yanse;
if (value<=7)
yanse = '#81d135';
if (value>7 && value<=14)
yanse = '#fdc159';
if (value>14)
yanse = '#fb6376';
cans.strokeStyle = yanse;
cans.fillStyle = yanse;
cans.lineWidth = 2;
cans.stroke(); //(a^2 + c^2 - b^2) / (2·a·c)
var jiajiao = Math.round( Math.acos( (Square(banjing)+ Square(banjing) - Square(4)) / (2*banjing*banjing) ) * 180/Math.PI );
//alert(jiajiao);
} function Drawscaleline(yuanxinx,yuanxiny, banjing, kaishijd, jieshujd, dengfen, yanse)
{
var can = $$(canid);
var cans = can.getContext('2d');
for (var i=0;i<dengfen;i++)
{
dfjd = ((jieshujd - kaishijd)/dengfen)*i;
cans.beginPath();
cans.arc(yuanxinx,yuanxiny,banjing, (Math.PI*2)*((kaishijd+dfjd)/360),(Math.PI*2)*((kaishijd+dfjd+1)/360),false);
cans.strokeStyle = yanse;
cans.lineWidth = 20;
cans.stroke();
}
} function DrawText(yuanxinx,yuanxiny, banjing, jiaodu, text, g)
{
var can = $$(canid);
var cans = can.getContext('2d');
cans.font = "bold 10px Arial";
cans.strokeStyle = g;
cans.fillStyle = g;
var jcbanjing = banjing -15;
x1 = yuanxinx + jcbanjing * Math.cos((jiaodu * Math.PI)/180.0);
//if (jiaodu>90)
// x1 = x1 +10;
//else
// x1 = x1-18;
y1 = yuanxiny - jcbanjing *Math.sin((jiaodu * Math.PI)/180.0);
cans.fillText(text,x1,y1);
} function dashboard(id)
{
canid = id;
var can = $$(canid);
var banjing = (can.width/2);
var yuanxinx = can.width/2;
var yuanxiny = can.height;
var cans = can.getContext('2d');
pageLoad2(yuanxinx,yuanxiny,banjing-40,(Math.PI*2)*(180/360),(Math.PI*2)*(240/360),false,'#81d135');
pageLoad2(yuanxinx,yuanxiny,banjing-40,(Math.PI*2)*(240/360),(Math.PI*2)*(300/360),false,'#fdc159');
pageLoad2(yuanxinx,yuanxiny,banjing-40,(Math.PI*2)*(300/360),(Math.PI*2)*(360/360),false,'#fb6376'); Drawscaleline(yuanxinx,yuanxiny,banjing-40,180,240,6, '#6db52b');
Drawscaleline(yuanxinx,yuanxiny,banjing-40,240,300,6, '#f4bd5f');
Drawscaleline(yuanxinx,yuanxiny,banjing-40,300,361,6, '#ef5469'); Drawarc(yuanxinx,yuanxiny,banjing-62,12,21); Drawarc1(yuanxinx,yuanxiny,banjing-62,12,21); DrawText(yuanxinx,yuanxiny,banjing,180, '0', '#81d135');
DrawText(yuanxinx,yuanxiny,banjing,120, '7', '#fdc159');
DrawText(yuanxinx,yuanxiny,banjing,60, '14', '#fdc159');
DrawText(yuanxinx,yuanxiny,banjing,0, '21', '#fb6376'); //cans.scale(0.2, 0.2);
} function load()
{
dashboard('can');
dashboard('can1');
}
</script>
<body onload="load();" style="width:100%">
<canvas id="can" width="414px" height="310px"></canvas>
<canvas id="can1" width="414px" height="310px"></canvas>
</body>
</html>

数学还勉强管用,用代码还能画个canvas 仪表盘(含完整代码)的更多相关文章

  1. 二叉查找树 C++实现(含完整代码)

    一般二叉树的查找是通过遍历整棵二叉树实现,效率较低.二叉查找树是一种特殊的二叉树,可以提高查找的效率.二叉查找树又称为二叉排序树或二叉搜索树. 二叉查找树的定义 二叉排序树(Binary Search ...

  2. Spring Data JPA基本增删改查和JPQL查询(含完整代码和视频连接)

    问题:SpringDataJPA怎么使用? 一.考察目标 主要考核SpringDataJPA的用法 二.题目分析 spring data jpa 的使用步骤(下面有具体实现细节) 1.创建maven工 ...

  3. C语言实现推箱子游戏完整代码

    C语言实现推箱子游戏完整代码 前言 自己做的,可能有些代码不够工整,或者有些小问题,但游戏的基本操作是可以实现的 代码效果 代码一共分为8个部分,4个控制上下左右移动,2个判断输赢,1个统计归为的个数 ...

  4. java中异常抛出后代码还会继续执行吗

    今天遇到一个问题,在下面的代码中,当抛出运行时异常后,后面的代码还会执行吗,是否需要在异常后面加上return语句呢? public void add(int index, E element){ i ...

  5. ClownFish:比手写代码还快的通用数据访问层

    http://www.cnblogs.com/fish-li/archive/2012/07/17/ClownFish.html 阅读目录 开始 ClownFish是什么? 比手写代码还快的执行速度 ...

  6. location.href 跳转之后,原来位置下面的代码还会继续执行

    location.href 跳转之后,原来位置下面的代码还会继续执行

  7. 除了降低成本和加速数字化转型,低代码还能给企业带来什么价值 ZT

    翻译自:https://dzone.com/articles/measuring-the-roi-of-low-code-1,有删改 低代码 是一种近些年兴起的企业软件快速开发技术和工具.借助低代码使 ...

  8. GitHub C 和 C++ 开源库的清单(含示例代码)

    内容包括:标准库.Web应用框架.人工智能.数据库.图片处理.机器学习.日志.代码分析等. 标准库 C++标准库,包括了STL容器,算法和函数等. C++ Standard Library:是一系列类 ...

  9. 【零基础】AI神经元解析(含实例代码)

    一.序言 关于“深度学习”大部分文章讲的都云里雾里,直到看到“床长”的系列教程以及<深度学习入门:基于Python的理论与实现>,这里主要是对这两个教程进行个人化的总结,目标是让“0基础” ...

随机推荐

  1. 3 Django 简介

    MVC 与 MTV 模型 MVC Web 服务器开发领域里著名的 MVC 模式,所谓 MVC 就是把 Web 应用分为模型 (M),控制器(C) 和视图 (V) 三层,他们之间以一种插件式的.松耦合的 ...

  2. 团体程序设计天梯赛L2-024 部落 2017-04-18 11:31 274人阅读 评论(0) 收藏

    L2-024. 部落 时间限制 120 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 在一个社区里,每个人都有自己的小圈子,还可能同时属于很多不 ...

  3. ZOJ3708:Density of Power Network

    The vast power system is the most complicated man-made system and the greatest engineering innovatio ...

  4. js 倒计时,转义

    function leftTimer(time) { var leftTime = (new Date(time)) - (new Date()); //计算剩余的毫秒数 var days = par ...

  5. bash shell & 环境变量

    root是没有~/.bashrc的,只. /etc/profile即可,/etc/profile和~/.bashrc的作用类似,只是作用域不同,都是写死的export,也有动态的脚本去设置命令和环境变 ...

  6. vim编辑后权限不够保存问题解决方案

    常常忘记了sudo就直接用vim编辑/etc内的文件,等编辑好了,保存时候才发现没权限. 1.曲线救国:先保存个临时文件,退出后再sudo cp回去 2.可以直接用 :w !sudo tee % 查阅 ...

  7. ping使用

    while read line do ip=`echo $line | awk '{print $2}' ` -i $ip ];then echo $line | tee -a b fi

  8. python文件备份与简单操作

    #!/usr/bin/python # -*- coding: utf-8 -*- # data:2018/8/30 # user:fei import sys import random num = ...

  9. mongodb 备份脚本

    ###############备份脚本#!/bin/bash basepath="/data/backup/dump$(date +%Y%m%d%H%M%S)" if [ ! -d ...

  10. 【OCP题库】最新CUUG OCP 12c 071考试题库(67题)

    67.(25-8)choose the best answer: View the Exhibit and examine the structure of CUSTOMERS table. Eval ...