canvas制作饼图和环形图,使用Excanvas兼容IE67
excanvas 地址:http://excanvas.sourceforge.net/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>canvas</title>
<style>
</style> <!--[if lte IE 9]>
<script src="../html5shiv.js"></script>
<script src="excanvas.js"></script>
<script src="../jquery-1.11.0.min.js"></script>
<!--[if gt IE 9]><!-->
<script src="../jquery-2.1.0.min.js"></script>
<![endif]-->
</head> <body>
<canvas id="pie" width="100" height="100" data-ratio="0.65_0.15_0.20" ></canvas>
<canvas class="doughnut" width="100" height="100" data-ratio="0.66_0.34"></canvas>
<script>
(function($){
$.fn.extend({
pieChart: function(o){
this.each(function(m, n){
var target = $(n),
ratio = target.data('ratio').split('_'),
colors = o.colors,
ctx = n.getContext('2d'),
center = Math.floor(target.height()/2), //圆心
radius = center - (o.borderWidth || 0), //半径
startAngle = Math.PI * 1.5, //起始弧度
endAngle = Math.PI * 1.5; //结束弧度 ctx.fillStyle = o.borderCorlor || '#ffffff';
ctx.arc(center, center, center, 0, Math.PI * 2, true);
ctx.fill(); $.each(ratio, function(i, v){
endAngle = endAngle - v * Math.PI * 2; //结束弧度
ctx.fillStyle = colors[i];
ctx.beginPath(); ctx.moveTo(center, center); //移动到到圆心
ctx.arc(center, center, radius, startAngle, endAngle, true);
ctx.closePath();
ctx.fill(); if(o.stroke){
ctx.strokeStyle = o.stroke.color || '#ffffff';
ctx.lineWidth = o.stroke.width || 1;
ctx.stroke();
}
startAngle = endAngle; //设置起始弧度
});
}); }, doughnutChart: function(o){
this.each(function(m, n){
var target = $(n),
ratio = target.data('ratio').split('_'),
colors = o.colors,
ctx = n.getContext('2d'),
center = Math.floor(target.height()/2),
radius = center,
startAngle = Math.PI * 1.5,
endAngle = Math.PI * 1.5; $.each(ratio, function(i, v){
//弧度 = 角度 * Math.PI / 180
//v*360*Math.PI/180 = v * Math.PI * 2
endAngle = endAngle - v * Math.PI * 2;
ctx.fillStyle = colors[i];
ctx.beginPath(); ctx.moveTo(center, center);
ctx.arc(center, center, radius, startAngle, endAngle, true);
ctx.closePath();
ctx.fill();
startAngle = endAngle;
}); ctx.fillStyle = o.centerColor;
ctx.beginPath();
ctx.arc(center, center, radius-o.borderWidth, 0, Math.PI * 2, true);
ctx.fill();
});
}
}); $(window).on('load', function(){
$('#pie').pieChart({
colors: ['#7cb228', '#abd667', '#ededed'],
borderWidth: 2,
borderCorlor: '#7cb228'
// stroke: {
// color: '#ff0000',
// width: 2
// }
}); $('.doughnut').doughnutChart({
colors: ['#7cb228', '#ededed'],
centerColor: '#ffffff',
borderWidth: 10
});
});
})(jQuery); </script>
</body>
</html>
canvas制作饼图和环形图,使用Excanvas兼容IE67的更多相关文章
- Java 在Excel中添加分离型饼图、环形图
一.概述 Excel中可支持多种不同类型的图表,本文介绍如何绘制分离型饼图和环形图.其中,分离型饼图的绘制可分为整体分离型(即设置饼图分离程度)和局部分离(即设置点爆炸型值)两种情况.下面将以Java ...
- echart 折线图、柱状图、饼图、环形图颜色修改
之前在做报表的时候用过echart 用完也就完了,而这次在用的时候已经忘了,所以这里简单记录一下,好记性不如烂笔头!!! 1.折线图修改颜色: xAxis: { type: 'category', b ...
- canvas制作柱形图/折线图/饼状图,Konva写动态饼状图
制作饼状图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- echarts白色实心环形图(空心饼图)的编写
// 数据接入机构统计let myDom = document.getElementById('myChart');let myWidth = myDom.offsetWidth - 5; // 获取 ...
- html5实现饼图和线图
html5实现饼图和线图-我们到底能走多远系列(34) 我们到底能走多远系列(34) 扯淡: 送给各位一段话: 人生是一个不断做加法的过程 从赤条条无牵无挂的来 到学会荣辱羞耻 ...
- 用Canvas制作简单的画图工具
今天用Canvas制作了一个画图工具,非常简单,功能也不是很多,主要有背景网格,画线,画圆,画矩形和画圆角矩形,也用到了canvas的一些基本知识,在这里一一列举. 1.线段的绘制: 如何绘制真正的1 ...
- Vue+WebSocket+ES6+Canvas 制作「你画我猜」小游戏
Vue+WebSocket+ES6+Canvas 制作「你画我猜」小游戏 转载 来源:jrainlau 链接:https://segmentfault.com/a/1190000005804860 项 ...
- echarts实现环形图
前端框架使用的angular,使用echarts实现环形图 1. item.component.html <div id="box1" class="pie&quo ...
- HTML5 canvas制作童年的回忆大风车
今天看到一篇CSS3写的大风车http://www.cnblogs.com/yaojaa/archive/2013/01/30/2882521.html,感觉CSS3太神奇了,这在以前用CSS是想都不 ...
随机推荐
- Product Device Lot
Product是指产品: 这个Product可以在不同的设备类型上生产, 同一类型的设备也可能硬件有差异,所以会有相对应的Device(Recipe): 同一Product(或同一Device)由于数 ...
- Quartz中时间参数说明 即Cron表达式
Cron表达式 Quartz使用类似于Linux下的Cron表达式定义时间规则,Cron表达式由6或7个由空格分隔的时间字段组成,如表1所示: 表1 Cron表达式时间字段 位置 时间域名 允许值 允 ...
- CSS——ul(demo)
1.ul本身是块级元素,在实际运用中,我们不设定宽高的话,它的宽就是父元素的宽,它的高就是内容撑起来的高度. 2.在局部布局的时候,我们可以不用设定ul的宽度和高度,直接使用margin来巧妙布局. ...
- CSS——属性选择器
属性选择器:通过对标签中属性的选择,控制标签. <!DOCTYPE html> <html> <head> <style> div[class*=&qu ...
- 2016.01.08 Javascript视频
完成JavaScript开发视频课程的Ajax部分内容.
- Logstash_Apache日志采集
[root@Cagios logstash-]# cat /usr/local/logstash-/logstash_agent.conf input { file { type => &quo ...
- (转)分布式文件存储FastDFS(四)配置fastdfs-apache-module
http://blog.csdn.net/xingjiarong/article/details/50560605 在前边我们已经配置好了FastDFS的环境,但是此时的FastDFS还不能通过htt ...
- PHP 之simple_html_dom实现网页数据采集
<?php set_time_limit(0); include './simple_html_dom.php'; $url = 'https://price.pcauto.com.cn/pri ...
- CorelDRAW 中文官网 618 48H秒杀开始,多重好礼即刻开抢!
618我有诚意,你呢? 不花钱的618,是残缺的618 给自己一个放肆shopping的机遇 活动力度不够大? 继续升级,终极体验 6月17日—6月18日 618疯狂48小时! 同志们,如果你错过 ...
- vim三种模式
一般模式 以vi打开一个文件就直接进入一般模式了.一般模式下可以移动光标查看内容,通过ESC回到一般模式. 一般模式下常用的操作: 撤销与重做 命令 说明 u 复原上一个操作 . 小数点 重复上一个操 ...