案例如图:

<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();
}

转载于:https://www.cnblogs.com/xiaomaotao/p/7018667.html

Canvas 画占比图 解决canvas锯齿 bug相关推荐

  1. 微学习 Canvas [环形占比图]

    Canvas [环形占比图] View代码 CSS代码 Script代码 效果展示 View代码 <template><canvas class="canvas" ...

  2. 如何用 canvas 画出分形图

    前言 分形是一门以非规则几何形态为研究对象的几何学,由曼德勃 罗(B.B.Mandelbrot)等人创立并命名. 分形图从整体上看,是处处不规律的.但从局部观察,图形的规则性又是相同的,即具有自相似的 ...

  3. 用Canvas画占百分比的圆形比例

    先看一下效果图: 开发流程及主要思想 第一步:先画一个背景 第二步:占比例的圆的是从圆的正上方开始的画的,而默认情况下画的圆是从圆心的右边开始画的,所以要将圆旋转设置-90度,也就是 -Math.PI ...

  4. 用html5 canvas画猪头,使用HTML5 Canvas实现画图效果

    使用HTML5可以非常简单地在canvas上实现画图应用,用支持html5的浏览器便可在下面的区域进行绘画,要看到演示效果,请确保你的浏览器支持HTML5: 效果演示 您的浏览器不支持canvas! ...

  5. 毛边效果 html,Html5 Canvas画线有毛边解决方法

    例外参考:http://jo2.org/html5-canvas%E7%94%BB%E5%9B%BE3%EF%BC%9A1px%E7%BA%BF%E6%9D%A1%E6%A8%A1%E7%B3%8A% ...

  6. 毛边效果 html,详解Html5 Canvas画线有毛边解决方法

    Html5 Canvas 所有的画线指令画出来的线条都有毛边(比如 lineTo, arcTo,strokeRect),这是因为在Canvas中整数坐标值对应的位置恰巧是屏幕象素点中间的夹缝,那么当按 ...

  7. Html5 Canvas画线有毛边解决方法

    例外参考:http://jo2.org/html5-canvas%E7%94%BB%E5%9B%BE3%EF%BC%9A1px%E7%BA%BF%E6%9D%A1%E6%A8%A1%E7%B3%8A% ...

  8. 微信小程序使用canvas画海报分享图

    项目场景: 很多小程序都会有一些分享海报的需求.因为我这边之前一直都是后端直接生成一张图片然后返回了的,我前端直接把路径放上去就可以了.但是,有时候后端没直接生成海报,而是只生成了一个二维码,这时候就 ...

  9. 为什么python画不了图-解决python中使用plot画图,图不显示的问题

    python matplotlib画的图怎么显示不出来 初学python,matplotlib库画图不显示分享助别熬夜了,你等不来的人,等到多晚都不会来的. 见图.python matplotlib ...

最新文章

  1. 【Android 安全】DEX 加密 ( Java 工具开发 | 解压 apk 文件 | 加密生成 dex 文件 | 打包未签名 apk 文件 | 文件解压缩相关代码 )
  2. Stanford UFLDL教程 独立成分分析
  3. Vue第二章,在项目中使用element-ui组件
  4. oracle中的null 字段,Oracle下的NULL字段
  5. pypark hive 开启动态分区_Hive分区与分桶
  6. java中单例模式的3种实现
  7. C++ 0x 使用可变参数模板类 实现 C# 的委托机制
  8. Python实战从入门到精通第十八讲——改变对象的字符串显示
  9. ubuntu skill
  10. ldd usr bin mysql_ldd与otool
  11. 小米浏览器禁止java,如何禁止小米手机浏览器中弹出窗口广告
  12. ise 检查文件语法错误
  13. 剪辑视频,垂直翻转如何实现
  14. 天池O2O优惠券预测之后的一些个人思考
  15. linux下scala脚本运行报错error: expected class or object definition 解决方案
  16. 一键生成IOS App Icon工具
  17. 为什么月薪2万的大数据职位都必须学习Python?
  18. 历时半年,我的IT编程自学平台终于来了
  19. 【新书】崛起的超级智能:互联网大脑如何影响科技未来
  20. yii2高级模板安装和yii migrate的使用

热门文章

  1. IIS 6.0 访问aspx页面出现404错误
  2. java获取硬盘序列号_Win7 64+Python3.7获取计算机硬盘信息初探
  3. python项目开发案例集锦_在线分享 | 在 VS Code 中一站式完成 Python 项目开发
  4. c语言动态存储分配和链表,C语言静态链表和动态链表
  5. php数组基础知识,PHP 数组基础知识小结
  6. java link_Java Link类代码示例
  7. a标签获取input值_HTML5常用标签
  8. Java基础知识融合(Arraylist集合,多态,继承,封装,包装类,循环嵌套,if嵌套等等)
  9. mysql inputoutput_PHP:同时使用INPUT和OUTPUT参数(不“ INOUT”)调用MySQL存储过程
  10. Shell 脚本案例实战 [4]