画布局部圆
Canvas partial circle
本文关键字:布局部 更新时间:2023-09-26
所以,我有一些js代码来绘制一个指定百分比的圆圈,我的问题是,我希望空的部分也用指定的颜色填充。面积
下面是我的代码: HTML:<!DOCTYPE html>
<html>
<script src="ion.js"></script>
<canvas data-width="5" data-ringcolor="blue" data-filledcolor="1" data-precentage="90" onclick="createNewChart( this, 40 );">
</canvas>
</html>
JS:
function createNewChart( elemnt, radius )
{
if( elemnt.getAttribute( "data-ringcolor" ) && elemnt.getAttribute( "data-filledcolor" ) && elemnt.getAttribute( "data-precentage" ) && elemnt.getAttribute( "data-width" ) )
{
var percentage = Number( elemnt.getAttribute( "data-precentage" ) );
var ctx = elemnt.getContext( "2d" );
ctx.beginPath( );
ctx.arc( 95, 50, radius, 0, ( ( percentage / 100 ) * 2 ) * Math.PI );
ctx.strokeStyle = elemnt.getAttribute( "data-ringcolor" );
ctx.lineWidth = Number( elemnt.getAttribute( "data-width" ) );
ctx.stroke();
}
else
{
alert( "Missing attribute!" );
}
}
像这样添加另一个路径:
function createNewChart( elemnt, radius )
{
if( elemnt.getAttribute( "data-ringcolor" ) && elemnt.getAttribute( "data-filledcolor" ) && elemnt.getAttribute( "data-precentage" ) && elemnt.getAttribute( "data-width" ) )
{
var percentage = Number( elemnt.getAttribute( "data-precentage" ) );
var ctx = elemnt.getContext( "2d" );
ctx.beginPath( );
ctx.arc( 95, 50, radius, 0, ( ( percentage / 100 ) * 2 ) * Math.PI );
ctx.strokeStyle = elemnt.getAttribute( "data-ringcolor" );
ctx.lineWidth = Number( elemnt.getAttribute( "data-width" ) );
ctx.stroke();
ctx.beginPath( );
ctx.arc( 95, 50, radius, ( percentage / 100 ) * 2 * Math.PI, 2 * Math.PI );
ctx.strokeStyle = "red";
ctx.lineWidth = Number( elemnt.getAttribute( "data-width" ) );
ctx.stroke();
}
else
{
alert( "Missing attribute!" );
}
}
相关文章:
- 如何解雇“;铁局部存储负载”;事件
- Javascript用函数return替换局部变量
- 每次调用函数时,都要修改Javascript中的局部变量
- 局部变量在闭包中丢失
- 试图将一个局部变量传递给我的ngAside控制器
- 如何将Node.js与卡布奇诺一起使用
- jQuery.ajax()访问javascript循环中的beforeEnd局部变量
- 变量只能在函数中局部工作,不能全局工作-Javascript
- 无法删除逗号'在菲兹布兹
- Ng包含不使用phantomjs进行局部渲染
- 对于使用传递的数据计算的局部范围变量,角度绑定在自定义指令中不起作用
- 如何通过JS将值传递给控制器和局部视图
- 如何在angularjs中调用局部视图所需的另一个javascript
- 如何使用局部变量创建全局变量
- 局部全局变量问题 - JavaScript
- 局部数组变量不是数组
- 如何在单击链接后将局部变量发送到部分呈现
- 定义 JavaScript 类的局部变量
- 代码学院的石头剪刀布
- 石头剪刀布游戏功能在Javascript