HTML5 Canvas采用面向对象的Web图表代码



113 448 150



特效描述:HTML5 Canvas 采用面向对象 Web图表代码,1.时态图表、动画图表 2.复合图表,可以多种图表组合,表达更为详细的数据信息 3.颜色表,通过色带的方式,方便用户对多种数据风格的指定,达到理想的风格 4. 5.支持Java OC版本,这样可以满足多种开发方式和平台的选择

代码结构

1. 引入CSS

<link rel="stylesheet" href="theme/default/style.css" type="text/css">
<link rel="stylesheet" href="theme/default/style.css" type="text/css">

2. 引入JS

<script type="text/javascript" src="lib/OpenCharts.js"></script>
<script type="text/javascript" src="lib/OpenCharts.js"></script>

3. HTML代码

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        var charts,charts1,charts2,charts3,charts4,charts5 ;
        function init()
        {
            var items = [],items1 = [],items2 = [],items3 = [];
            var style = new OpenCharts.Style();
            style.fillStyle = "#F00";
            items.push({strCaption : '一月',data : 2,itemStyle:'#C0FFFF'});
            items.push(new OpenCharts.Item(12,"二月",style));
            items.push(new OpenCharts.Item(14,"三月","#FFC000"));
            items.push(new OpenCharts.Item(20,"四月","#FFFF00"));
            items.push(new OpenCharts.Item(28,"五月","#92D050"));
            items.push(new OpenCharts.Item(32,"六月","#00B050"));
            items.push(new OpenCharts.Item(34,"七月","#00B0F0"));
            items.push(new OpenCharts.Item(36,"八月","#0070C0"));
            items.push(new OpenCharts.Item(33,"九月","#002060"));
            items.push(new OpenCharts.Item(24,"十月","#7030A0"));
            items.push(new OpenCharts.Item(14,"十一月","#C0504D"));
            items.push(new OpenCharts.Item(4,"十二月","#F79646"));
            var itemss = [];
            itemss.push({data : 4,itemStyle:'#dad81f'});
            itemss.push({data : 16});
            itemss.push({data : 18});
            itemss.push({data : 20});
            itemss.push({data : 32});
            itemss.push({data : 36});
            itemss.push({data : 38});
            itemss.push({data : 38});
            itemss.push({data : 36});
            itemss.push({data : 26});
            itemss.push({data : 20});
            itemss.push({data : 14});
            var itemsss = [];
            itemsss.push({data : 1,itemStyle:'#76a871'});
            itemsss.push({data : 12});
            itemsss.push({data : 18});
            itemsss.push({data : 20});
            itemsss.push({data : 28});
            itemsss.push({data : 34});
            itemsss.push({data : 36});
            itemsss.push({data : 34});
            itemsss.push({data : 31});
            itemsss.push({data : 27});
            itemsss.push({data : 24});
            itemsss.push({data : 6});
            //myCanvas.addEventListener("mousedown",OnMouseDown,false);
            charts = new OpenCharts.Chart.PieChart("canvas",{smooth:true});
            charts.strTitle = "Hello World";
            charts.smooth = true;
            //charts.titleStyle.fColor = "#000";
            var message = "${itemName}${itemCaption}的气温是${itemData}C";
            charts.addItems(items,"北京");
            //charts.addItems(itemss,"上海");
            //charts.addItems(itemsss,"西安");
            charts.addEventListener("mousedown",message);
            //charts.addEventListener("mousemove",message);
            //myCanvas.addEventListener("mousedown",OnMouseDown,false);
            charts1 = new OpenCharts.Chart.AreaChart("canvas1");
            charts1.strTitle = "Hello OpenCharts";
            charts1.addItems(items,"北京");
            charts1.addItems(itemss,"上海");
            charts1.addItems(itemsss,"西安");
            charts1.addEventListener("mousedown",message);
            charts2 = new OpenCharts.Chart.LineChart("canvas2");
            charts2.strTitle = "Hello Sunday";
            charts2.addItems(items,"北京");
            charts2.addItems(itemss,"上海");
            charts2.addItems(itemsss,"中华人民共和国陕西省西安市");
            charts2.addEventListener("mousedown",message);
            charts2.showLegend(true);
            charts2.bAnimation = true;
            charts3 = new OpenCharts.Chart.BarChart("canvas2");
            charts3.strTitle = "Hello My Github";
            //charts3.showLegend(false);
            charts3.addItems(items,"北京");
            //charts3.addItems(itemss,"上海");
            //charts3.addItems(itemsss,"西安");
            charts3.addEventListener("mousedown",message);
            charts4 = new OpenCharts.Chart.BarExChart("canvas4");
            charts.bAnimation = charts1.bAnimation = charts2.bAnimation = charts3.bAnimation = charts4.bAnimation = true;
            charts.render();
            charts1.render();
            //charts2.render();
            charts3.bAnimation = false;
            //charts3.render();
            charts5 = new OpenCharts.Chart.CompoundChart();
            charts5.addCharts(charts3);
            charts5.addCharts(charts2);
            charts5.render();
            items = [];
            items.push({strCaption : '上海',data : 11461.39,itemStyle:'#002060'});
            items.push(new OpenCharts.Item(33444.79,"北京",style));
            items.push(new OpenCharts.Item(3261.26,"四川","#FFC000"));
            items.push(new OpenCharts.Item(2448.86,"山西","#FFFF00"));
            items.push(new OpenCharts.Item(1392.13,"天津","#92D050"));
            items.push(new OpenCharts.Item(3092.94,"山东","#00B050"));
            items.push(new OpenCharts.Item(13113.26,"广东","#00B0F0"));
            items.push(new OpenCharts.Item(3631.0,"江苏","#0070C0"));
            items.push(new OpenCharts.Item(1882.03,"湖北","#002060"));
            items.push(new OpenCharts.Item(3606.78,"浙江","#7030A0"));
            items.push(new OpenCharts.Item(1485.74,"辽宁","#C0504D"));
            items.push(new OpenCharts.Item(1673.03,"河南","#F79646"));
            charts4.strTitle = "各省市上市公司总市值";
            //charts4.showLegend(false);
            message = "${itemName}${itemCaption}的上市公司总市值为${itemData}(亿)";
            charts4.addItems(items,"");
            charts4.addEventListener("mousedown",message);
            charts4.render();
        }
    </script>
</head>
<body onLoad="init()">
<div style="left:0px;top:0px;position: absolute;">
    <canvas id="canvas" height="300px" width="500px"  />
</div>
<div style="left:0px;top:330px;position: absolute;">
    <canvas id="canvas1" height="300px" width="500px"  />
</div>
<div style="left:510px;top:0px;position: absolute;">
    <canvas id="canvas2" height="300px" width="500px" left="550px" top="0xp" />
</div>
<div style="left:510px;top:330px;position: absolute;">
    <canvas id="canvas3" height="300px" width="500px" left="550px" top="330xp" position="absolute" />
</div>
<div style="left:1020px;top:0px;position: absolute;">
    <canvas id="canvas4" height="600px" width="500px" left="1040px" top="0xp" position="absolute" />
</div>
</body>
</html>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 瀑布流 收藏 预览 自适应页面大小 响应式区块列表布局 摇摆 烟花 清单样式 照相机 注释 下划线 结构图 鼠标悬停 条形码 弹幕 画板 朋友圈样式 红包 css绘制样式 支付 图文布局 右键菜单 二维码 文字提示框 地图 提示框/弹出层 计算器 layer 计时器 lightbox 桌面 跳转 Tooltip工具提示框 步骤 浮动提示框 键盘 html5弹窗动画 签到 分享 点赞 投票 雪花 打印 答题 震动 图表 鼠标滑过 抽奖 表情 qq空间 头像截图 星星打分评分 编辑器 播放器 电子杂志 排行榜 分页翻页 排序 表格隔行变色 table表格 进度条 多功能 弹出层拖动 窗口提示框 滑动星星打分 其他更多

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到