Canvas 画占比图 解决canvas锯齿 bug
案例如图:
<section class=" chartWrap">
<div class="chartContent">
<div class="chartInfo">
<canvas class="canvasVip " id="chartEl" width="240" height="240">你的浏览器不支持canvas</canvas>
<div class="moneyInfo">
<div class="moneyInfoUp">
<p class="nowAbleTips">可用额度</p>
<strong ><em>¥</em><span class="nowAblePay">20000</span></strong>
</div>
<div class="moneyInfoDown">
<p class="overBorrow">已认证额度</p>
<strong ><em>¥</em><span class="borrowMoney">50000</span></strong>
</div>
</div>
</div>
</div>
</section>
===============style===================
@charset "utf-8";
/* 禁用iPhone中Safari的字号自动调整 */
html {
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
/* 去除iPhone中默认的input样式 */
input[type="submit"], input[type="reset"], input[type="button"], input {
-webkit-appearance: none;
resize: none;
}
/* 局部滚动使用弹性滚动效果 */
body{-webkit-overflow-scrolling:touch;}
/* 取消链接高亮 */
body, div, ul, li, ol, h1, h2, h3, h4, h5, h6, input, textarea, select, p, dl, dt, dd, a, img, button, form, table, th, tr, td, tbody, article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
/* 设置HTML5元素为块 */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
}
/* 图片自适应 */
img {
width: 100%;
height: auto;
width: auto\9; /* ie8 */
-ms-interpolation-mode: bicubic;/*为了照顾ie图片缩放失真*/
}
/* 初始化 */
body, div, ul, ol, h1, h2, h3, h4, h5, h6, input, textarea, select, p, dl, dt, dd, a, img, button, form, table, th, tr, td, tbody, article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
margin: 0;
padding: 0;
border: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-size: 12px;
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC","Helvetica Neue",STHeiti,"Microsoft Yahei",Tahoma,Simsun,sans-serif;
color: #555;
background-color: #F7F7F7;
}
em, i {
font-style: normal;
}
strong {
font-weight: normal;
}
.clearfix:after {
content: "";
display: block;
visibility: hidden;
height: 0;
clear: both;
}
.clearfix {
zoom: 1;
}
a {
text-decoration: none;
color: #969696;
font-family: '宋体', Microsoft YaHei, Tahoma, Arial, sans-serif;
}
a:hover {
color: #FED503;
text-decoration: none;
}
ul, ol {
list-style: none;
}
h1, h2, h3, h4, h5, h6 {
font-size: 100%;
font-family: Microsoft YaHei;
}
img {
border: none;
}
/*清除浮动*/
.clearfix{*zoom:1;}.clearfix:after,.clearfix:before{display:block; content:"clear"; height:0; clear:both; overflow:hidden; visibility:hidden;}.z{_zoom:1;}
/*连续英文、数字换行*/
.wordwrap { word-break: break-all; word-wrap: break-word; }
/*单行文字超出显示省略号*/
.omg{overflow: hidden; text-overflow: ellipsis; white-space:nowrap;}
/*水平对齐方式*/
.tc{text-align:center;}.tr{text-align:right;}.tl{text-align:left;}
/*垂直对齐方式*/
.vm{vertical-align:middle;}.vtb{vertical-align:text-bottom;}.vt{vertical-align:top;}.vn{vertical-align:-2px;}.vimg{margin-bottom:-3px;}
html{font-size: 40px;}
.box{width:200px;height: 200px;background: yellowgreen;margin:100px auto;}
/* 借款占比表 */
.chartWrap{margin-top:2.2rem;width:100%;height:320px;background-image:-webkit-linear-gradient(to bottom, #1B1C22, #2E3144); background-image:linear-gradient(to bottom, #1B1C22, #2E3144);}
.chartWrap h3{font-size: 0.75rem;font-weight:normal;color:#fff;text-align: center;padding:0.5rem 0 0.35rem;}
.chartWrap .chartInfo{position:relative;width:260px;height:260px;margin:0 auto;}
.chartWrap #chartEl{width:240px;height:240px;margin:10px;}
.chartWrap .moneyInfo{position:absolute;width:150px;height:150px;top:50%;left:50%;transform:translate(-50%,-50%);-webkit-transform:translate(-50%,-50%);color:#fff;font-size: 18px;text-align: center;}
.chartWrap .moneyInfo span{font-size: 36px;}
.chartWrap .moneyInfo em{font-size: 28px;}
.chartWrap .moneyInfo span.borrowMoney{font-size: 24px;}
.chartWrap .moneyInfo strong{font-size: 34px;}
.chartWrap .moneyInfo em{font-size: 22px;}
.chartWrap .moneyInfoUp{position:relative;padding-bottom: 10px;}
.chartWrap .moneyInfoUp:before{content:'';position:absolute;width:140px;height:3px;bottom:0;left:50%;transform:translate(-50%,0);-webkit-transform:translate(-50%,0);}
.chartWrap .moneyInfoDown{margin-top: 10px;}
.assessDateDes{display: none;font-size: 0.6rem;text-align: center;}
.chartWrap .goToDownApp{width:14.7rem;font-size: 0.65rem;height:1.6rem;text-align: center;line-height: 1.6rem;border-radius:5px;margin:0 auto;display: block;margin-top: 0.4rem;position:relative;}
.chartFooter .hiladyBtn{line-height: 1.6rem;text-indent:-0.6rem;}
.chartFooter .hiladyBtn:before{position:absolute;content:"";width:1.6rem;height:1.6rem;left:50%;border-radius:50%;background: url(../images/GO.png) 0 0 no-repeat;-webkit-background-size: cover;background-size: cover;top:50%;transform:translate(-50%,-50%);-webkit-transform:translate(-50%,-50%);}
.vipChart{height:340px;background-image:-webkit-linear-gradient(to bottom, #1B1C22, #2E3144); background-image:linear-gradient(to bottom, #1B1C22, #2E3144);}
.vipChart .moneyInfo em,.vipChart .moneyInfo span{color:#E6BC8A;}
.vipChart .chartFooter{display: none;}
.vipChart .moneyInfoUp:before{content:'';background: #E6BC8A;}
.driverChart{height:390px;background:#FFD000;color:#393B48;}
.driverChart .moneyInfoUp:before{content:'';background: #282828;}
.driverChart .hiladyBtn{display: none;}
.driverChart .ddsjBtn{color:#fff;background: #282828;display: block;}
.higirlChart{height:390px;background: #FCC0BD;color:#393B48;}
.higirlChart .moneyInfoUp:before{content:'';background: #393B48;}
.higirlChart .ddsjBtn{display: none;}
.higirlChart .hiladyBtn{color:#fff;background: #393B48;display: block;}
.couponAndGuide{padding-left:0.625rem;background: #fff;}
.couponAndGuide>div{height:1.95rem;line-height: 1.95rem;font-size: 0.65rem;color:#333;}
.couponAndGuide>div:nth-child(1){border-bottom: 1px solid #ddd;}
.couponAndGuide>div span{float: left;}
.couponAndGuide>div i{float: right;margin-right: 0.625rem;}
.couponAndGuide>div em.couponNum{float: right;font-size: 0.55rem;margin-right: 0.4rem;}
==========js======================
var usedAmount = $(".chartInfo span.nowAblePay").text(),
totleAmount = $(".chartInfo span.borrowMoney").text(),
usedAmountAnimate = 0,
chartColorB,
chartColorF,
canvasHiLoan = document.getElementById('chartEl');
/*判断产品 区分颜色 VIPD SJD 商城 */
var arrColorF = ['#E6BC8A','#282828','#393B48'],
arrColorB = ['#494C5E','#FFE368','#D8D8D8'];
var chartColorF = arrColorF[0] , chartColorB = arrColorB[0] ;
animateDraw(usedAmountAnimate, totleAmount, canvasHiLoan,chartColorB,chartColorF);
/*画chart方法*/
function animateDraw(usedAmountAnimate, totleAmount, canvasHiLoan) {
var ctx = canvasHiLoan.getContext('2d')
setInterval(function() {
if (usedAmountAnimate < usedAmount) {
usedAmountAnimate = usedAmountAnimate + 50;
drawCanvas(usedAmountAnimate, totleAmount);
};
}, 0.8)
function drawCanvas(usedAmountAnimate, totleAmount) {
var Ratio = usedAmountAnimate / totleAmount;
if (canvasHiLoan.getContext) {
ctx.beginPath();
ctx.lineCap = "round";
ctx.moveTo(120, 10);
ctx.arc(120, 120, 110, -0.5 * Math.PI, 1.5 * Math.PI, false);
ctx.lineWidth = 20;
ctx.strokeStyle = chartColorB;
ctx.stroke();
ctx.beginPath();
ctx.lineCap = "round";
ctx.moveTo(120, 10);
ctx.arc(120, 120, 110, -0.5 * Math.PI, (Ratio * 2 - 0.5) * Math.PI, false);
ctx.lineWidth = 20;
ctx.strokeStyle = chartColorF;
ctx.stroke();
}
}
/*消除锯齿*/
if (window.devicePixelRatio) {
var width = canvasHiLoan.width,
height = canvasHiLoan.height;
canvasHiLoan.height = height * window.devicePixelRatio;
canvasHiLoan.width = width * window.devicePixelRatio;
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
}
}
/*chart内三位加逗点不考虑小数点*/
thousandSpaces(".nowAblePay");
thousandSpaces(".borrowMoney");
/*金额千位逗点处理*/
function thousandSpaces(el) {
$(el).text($(el).text().replace(/[0-9]+?(?=(?:([0-9]{3}))+$)/g, function(a) {
return a + ','
}));
}
function getfont() {
var html1 = document.documentElement;
var screen = html1.clientWidth;
if (screen >= 640) {
html1.style.fontSize = '40px';
} else if (screen <= 320) {
html1.style.fontSize = '20px';
} else {
html1.style.fontSize = 0.0625 * screen + 'px';
}
}
getfont();
window.onresize = function() {
getfont();
}
Canvas 画占比图 解决canvas锯齿 bug的更多相关文章
- 关于设备与canvas画不出来的解决办法
连续四天解决一个在三星手机上面画canvas的倒计时饼图不出来的问题,困惑了很久,用了很多办法,甚至重写了那个方法,还是没有解决,大神给的思路是给父级加 "overflow: visible ...
- Canvas 画圆
原文地址:http://hi.baidu.com/lj2tj/item/557d8d1a65adfa721009b58b --------------------------------------- ...
- canvas画箭头demo
效果图: 代码: <!DOCTYPE html> <html> <title>canvas画箭头demo</title> <body> &l ...
- canvas画圆类似于锯齿指针 angular5
拿到图的时候大致是这样的,里面的圆是有动态效果的,考虑到gif图耗资源,于是想要用canvas画出来: 仔细看图不难发现,这个锯齿圆类似于表盘,计算好弧度,不难实现: 因为项目现在用的框架是angul ...
- 玩转html5(二)----用canvas结合脚本在画布上画简单的图(html5又一强大功能)
在html5中可以使用canvas标签在画布上画图,先直接上代码,这篇文章先简单介绍一下canvas的使用方法,简单画几个圆,矩形,三角形,写字. 在代码中均给出了注释,在这里特别强调的一点是:使用c ...
- Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形) .
1.首先说一下canvas类: Class Overview The Canvas class holds the "draw" calls. To draw something, ...
- Android利用canvas画各种图形 及Paint用法 .
引自:http://blog.csdn.net/carlfan/article/details/8139984 1.首先说一下canvas类: Class Overview The Canvas cl ...
- 10分钟,利用canvas画一个小的loading界面
首先利用定义下canvas得样式 <canvas width="1024" height="720" id="canvas" styl ...
- Android利用canvas画各种图形
Android利用canvas画各种图形(点.直线.弧.圆.椭圆.文字.矩形.多边形.曲线.圆角矩形) 本文链接:https://blog.csdn.net/rhljiayou/article/det ...
随机推荐
- Mybatis映射文件的自动映射与手动映射问题
Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会 ...
- 【win7】安装开发环境
1. 通用版主分支合并到v3,并删除data下无用文件或添加data有用文件 2. xampp php7与php5切换 是否可以行? 换phpstudy 默认支持php 32位,而我们要下载支持64的 ...
- springboot jpa 复合主键
https://blog.csdn.net/wyc_cs/article/details/9031991 创建一个复合主键类 public class LevelPostMultiKeysClass ...
- vue 点击当前元素添加class 去掉兄弟的class 获取当前点击元素的文字
点击当前标签给其添加class,兄弟标签class删除 然后获取当前点击元素的文字 演示地址: https://xibushijie.github.io/static/addClass.html &l ...
- 【Spring】Spring bean的实例化
Spring实现HelloWord 前提: 1.已经在工程中定义了Spring配置文件beans.xml 2.写好了一个测试类HelloWorld,里面有方法getMessage()用于输出" ...
- CF2B The least round way(dp+记录路径)
B. The least round way time limit per test 2 seconds memory limit per test 64 megabytes input standa ...
- 第七篇--ubuntu18.04下面特殊符号
按住键盘win键,在搜索框输入“字符”,弹出来的工具点进去 需要什么符号就找什么符号,然后点击它复制就好.
- vmware(1):vmware中的bridge、nat、host-only的区别
VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式) bridged(桥接模式) 在这种模式下,VMWare虚拟出来的操作系统就 ...
- qt: 系统默认程序打开文件或者软件;
Qt提供了QDesktopServices类, 可以利用openUrl函数调用默认程序打开文件: 源码参考: #ifdef Q_OS_WIN32 m_szHelpDoc = QString(" ...
- prometheus 基于文件的目标发现
prometheus 基于文件的目标发现 1.创建目录 cd /usr/local/prometheus/conf mkdir -pv targets/{nodes,docker} 2.修改prome ...