javaScript矢量图表库-gRaphael几行代码实现精美的条形图/饼图/点图/曲线图
2018-10-12 14:00
393 查看
gRaphael 是一个致力于帮助开发人员在网页中绘制各种精美图表的 Javascript 库,基于强大的 Raphael 矢量图形库。你只需要编写几行简单的代码就能创建出精美的条形图、饼图、点图和曲线图。
gRaphael 使用 SVG W3C 推荐标准和 VML 作为创建图形的基础,是跨浏览器的矢量图形库,目前支持的浏览器包括: Firefox 3.0+,Safari 3.0+,Chrome 5.0+,Opera 9.5+ 以及 Internet Explorer 6.0+。
使用方法:在页面中引入 raphael.js,g.raphael.js 文件,并根据需要引入 g.line.js(曲线图),g.bar.js(条形图),g.dot.js(点图)和 g.pie.js(饼图)文件,然后根据提供的方法即可创建出你想要的精美图表,下面是两个简单示例。
创建静态饼图只需要两行代码即可,示例代码:
// 在坐标(10,50)创建 600 × 450 的画布
var r = Raphael(10, 50, 600, 450);
// 创建中心坐标为(320, 200)的饼图,半径为150,数据为 [55, 20, 13, 32, 5, 1, 2, 10]的饼图
r.piechart(320, 240, 150, [55, 20, 13, 32, 5, 1, 2, 10]);
效果演示及完整源码下载:
源码下载
创建交互饼图
结合 hover 和 click 事件以及动画方法,你就可以创建精美的交互式饼图,示例代码:
// 在坐标(10,50)创建 640 × 480 的画布
var r = Raphael(10, 50, 640, 480);
// 创建中心坐标为(320, 240)的饼图,半径为100,数据为[55, 20, 13, 32, 5, 1, 2, 10]的饼图
pie = r.piechart(320, 240, 100, [55, 20, 13, 32, 5, 1, 2, 10], {
legend: ["%%.%% - Enterprise Users", "IE Users"],
legendpos: "west",
href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]
});
// 在坐标(320, 100)绘制文字
r.text(320, 100, "Interactive Pie Chart").attr({
font: "20px sans-serif"
});
// 给饼图添加 hover 事件
pie.hover(function() {
this.sector.stop();
this.sector.scale(1.1, 1.1, this.cx, this.cy);
if(this.label) {
this.label[0].stop();
this.label[0].attr({
r: 7.5
});
this.label[1].attr({
"font-weight": 800
});
}
}, function() {
this.sector.animate({
transform: 's1 1 ' + this.cx + ' ' + this.cy
}, 500, "bounce");
// 添加动画效果
if(this.label) {
this.label[0].animate({
r: 5
}, 500, "bounce");
this.label[1].attr({
"font-weight": 400
});
}
});
效果演示及完整源码下载:
源码下载
gRaphael 官方网站地址:http://g.raphaeljs.com/
gRaphael 英文参考文档:http://g.raphaeljs.com/reference.html
Raphael 官方网站地址:http://raphaeljs.com
Raphael 英文参考文档:http://raphaeljs.com/reference.html
Raphael 中文帮助文档:http://julying.com/lab/raphael-js/docs/
Raphael 新手入门教程:An Introduction to the Raphael JS Library
您可能感兴趣的文章:
- 详解Chart.js轻量级图表库的使用经验
- 常用的9个JavaScript图表库详解
- 使用Chart.js图表库制作漂亮的响应式表单
- JavaScript可视化图表库D3.js API中文参考
- Node.js开源应用框架HapiJS介绍
- 开源的javascript项目Kissy介绍
- Java中使用开源库JSoup解析HTML文件实例
- 利用noesis.Javascript开源组件.Net中执行javascript脚本
- jQuery EasyUI 开源插件套装 完全替代ExtJS
- 优秀js开源框架-jQuery使用手册(1)
- 一个加密JavaScript的开源工具PACKER2.0.2
- 4个顶级开源JavaScript图表库
相关文章推荐
- javaScript矢量图表库-gRaphael几行代码实现精美的条形图/饼图/点图/曲线图
- gRaphael——JavaScript 矢量图表库:两行代码实现精美图表
- 坐标下载gRaphael——JavaScript 矢量图表库:两行代码实现精美图表
- gRaphael——JavaScript 矢量图表库:两行代码实现精美图表
- 分享一个开源的JavaScript统计图表库,40行代码实现专业统计图表
- 简单几行javascript代码,实现动态倒计时功能
- gRaphael——JavaScript 矢量图表库
- gRaphael—JavaScript 矢量图表库
- Javascript+CSS实现漂亮带缓冲效果的图片展示代码
- JavaScript插入动态样式实现代码
- JavaScript在ASP页面中实现掩码文本框效果代码
- javascript实现动态模态绑定grid过程代码
- Android 仿今日头条视频播放控件JieCaoVideoPlayer(几行代码快速实现)
- javascript实现二分查找法实现代码
- 图文详解Heap Sort堆排序算法及JavaScript的代码实现
- Javascript 键盘事件的组合使用实现代码
- 【javascript】学习总结——动态时钟的实现代码
- 用javascript实现禁止页面后退返回上一页的代码
- JavaScript实现仿QQ折叠式菜单代码
- javascript克隆元素样式的实现代码