jquery flot pie画饼图

具体效果如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="javascript" type="text/javascript"src="jquery.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.pie.js"></script>

<script type="text/javascript">

	$(function(){

		var data = [
			{ label: "苹果",  data: 10},
			{ label: "香蕉",  data: 30},
			{ label: "西瓜",  data: 90},
			{ label: "葡萄",  data: 70},
			{ label: "柑橘",  data: 80},
			{ label: "菠萝",  data: 110}
		];

		$.plot($("#pie1"), data, {
			series: {
				         pie: {
									show: true //显示饼图
				         }
			},
			legend: {
						show: false //不显示图例
			}
		});

		$.plot($("#pie2"), data, {
			series: {
				pie: {
					show: true //显示饼图
				}
			}

		});

		$.plot($("#pie3"), data, {
			series: {
				pie: {
					show: true,
					radius: 1, //半径
					label: {
						show: true,
						radius: 2/3,
						formatter: function(label, series){
							return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
					},
					threshold: 0.03  //这个值小于0.03,也就是3%时,label就会隐藏
				}
			}
		},
		legend: {
			show: false
		}
	});

	 $.plot($("#pie4"), data,
	{
		series: {
			pie: {
				show: true
			}
		},
		grid: {
			hoverable: true,
			clickable: true
		}
	});

	$("#pie4").bind("plothover", pieHover);
	$("#pie4").bind("plotclick", pieClick);

	});

	function pieHover(event, pos, obj)
{
	if (!obj)
                return;
	percent = parseFloat(obj.series.percent).toFixed(2);
	$("#hover").html('<span style="font-weight: bold; color: '+obj.series.color+'">'+obj.series.label+' ('+percent+'%)</span>');
}

function pieClick(event, pos, obj)
{
	if (!obj)
                return;
	percent = parseFloat(obj.series.percent).toFixed(2);
	alert(''+obj.series.label+': '+percent+'%');
}

</script>

<style>
div.graph
		{
			width: 400px;
			height: 300px;
			border: 1px dashed gainsboro;
		}

</style>

</head>
<body>

<h3>饼图1</h3>
<div id="pie1" class="graph" ></div>
<hr>

<h3>饼图2</h3>
<div id="pie2" class="graph" ></div>
<hr>

<h3>饼图3</h3>
<div id="pie3" class="graph" ></div>
<hr>

<h3>饼图4</h3>
<div id="pie4" class="graph" ></div>
<div id="hover"></div>
<hr>

</body>
</html>
时间: 2024-08-24 15:47:59

jquery flot pie画饼图的相关文章

jquery flot 画柱状图

具体效果: 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></titl

iOS之画饼图

iOS之画饼图 1.效果图如下 2.画饼图实现步骤如下: 1.在main.storyboard中拖入一个UIView控件,并设置其Custom Class 为HMPieView.如下图 2.新建HMPieView类 // // HMPieView.h // 03-饼图 // #import <UIKit/UIKit.h> @interface HMPieView : UIView @end // // HMPieView.m // 03-饼图 // #import "HMPieVie

jquery.flot.js简介

JQuery图表插件之Flot Flot是一个Jquery下图表插件,具有简单使用,交互效果,具有吸引力外观特点.目前支持 Internet Explorer 6+, Chrome, Firefox 2+, Safari 3+ and Opera 9.5+ 等浏览器,是一个基于Javascript和Jquery纯客端户的脚本库,下面看一个简单的示例,先插入js: <script language="javascript" type="text/javascript&qu

JQuery Plugin serials (2)--- 图表插件(jquery.flot)使用

1)Download jquery.flot from github https://github.com/flot/flot 2) Tutorials for jquery.flot http://www.cnblogs.com/lwme/archive/2012/08/18/jquery-flot-plugin.html

canvas如何画饼图

画饼图,废话不多说,直接上代码和效果图 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>绘制弧线</title> <style type="text/css"> canvas{ border:1px solid #f00; } </style> </head> <body> &

(转)浅谈HTML5与css3画饼图!

神马系饼图? 饼图,大家都应该熟知,在统计数据对比方面,几乎处处用到.如cnzz的统计饼图 从饼图中,很形象地展示了访问者地区的分布,以扇形为块的方式拼成一个大圆. 都使用什么方法实现 目前众多站点制作饼图大多使用flash,或者后台语言生成,如PHP,Python只要安装相应的基础库就能实现画图.但很少有站点这么干,因为耗费服务器资源. cnzz里使用的就是flash PHP生成的 HTML5与CSS3也能画出饼图 不得不说,HTML5与CSS3的推出,将推翻老一代的网页制作者.特别在当今浏览

计算机图形学第四章练习——画饼图

计算机图形学第四章后边示例代码里有一段画饼图的练习,画出来是这样的 中间有一段中心画圆法未实现,搜集了网上资料补全并执行了这段代码,作为openGL的学习练习 #include <GL/glut.h> #include <stdlib.h> #include <math.h> GLsizei winWidth = 400, winHeight = 300; const GLdouble twoPi = 6.283185; class scrPt { public: GL

arcgis viewer for flex 之 自定义widget(arcmap设计pie圆饼图)

自定义Widget 终于可以实现第一个Widget了,按照惯例,我们通过一个Hello World Widget来说明如何在Flex Viewer中开发.编译.配臵.部署和使用自定义Widget.Flex Viewer的源代码中已经包含了一个HelloWorld Widget,我们还是亲手尝试一下吧. 1) 安装Flash Builder,下载Flex Viewer源码,我们使用最新的2.3: 2) 打开Flash Builder,导入Flex Viewer 2.3的源代码: 3) 鼠标放在wi

JQuery flot API文档 中文版

调用plot函数的方法如下: var plot = $.plot(placeholder, data, options) 其 中placeholder可以是JQuery的对象,DOM元素或者JQuery的表达示,要把完成的图放到这个位置上.placeholder要有宽度 和高度.因为plot会修改placeholder的一些属性,所以建议大家使用一个简单的div,除了高度和宽度其它的属性都不要设置. Data的结构: data应该是data series的一个数组: [ series1, ser