对ichartjs基于基于HTML5的开源图形组件画图的心得

简介:ichartjs 是一款基于HTML5的图形库。使用纯javascript语言, 利用HTML5的canvas标签绘制各式图形。如果你正在开发HTML5的应用,ichartjs正好适合您。chartjs是基于Apache License 2.0协议的开源项目。

心得用ichartjs画图就是参照ichartjs官网(http://www.ichartjs.com/samples/index.html)的示例中心的示例以及ichartjs API(http://www.ichartjs.com/docs/zh/html/menu.html)(注:各个类的参数)就可以画出你想要的图形。

注意现在项目中导入ichart.1.2.min.js库

示例:代码

[html]  view plain copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  3. <html>  
  4.   <head>  
  5.     <script type="text/javascript" src="ichart.1.2.min.js"></script>  
  6.     <script type="text/javascript">  
  7.             $(function(){  
  8.                   
  9.                 var data = [  
  10.                 {  
  11.                 name : '安全库存达成率',  
  12.                 value:[1.33,1.27,1.34,1.17,1.3,1.1,1.35,1.3,1.26,0.99],  
  13.                 color:'#db9034',  
  14.                 line_width:2  
  15.                 },  
  16.                 {  
  17.                 name : '安全库存率',  
  18.                 value:[1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25,1.25],  
  19.                 color:'#e0b645',  
  20.                 line_width:2  
  21.                 }  
  22.                 ];  
  23.                 var labels = ["2013年1月","2013年2月","2013年3月","2013年4月","2013 年 5 月","2013年6月","2013年7月","2013年8月","2013年9月","2013年10月"];  
  24.                 var chart = new iChart.LineBasic2D({  
  25.                 render : 'canvasDiv',  
  26.                 data: data,  
  27.                 align:'center',  
  28.                 title : {  
  29.                 text:'安全库存达成率',  
  30.                 fontsize:24,  
  31.                 color:'#f7f7f7'  
  32.                 },  
  33.                 width : 1000,  
  34.                 height : 400,  
  35.                 shadow:true,  
  36.                 shadow_color : '#20262f',  
  37.                 shadow_blur : 4,  
  38.                 shadow_offsetx : 0,  
  39.                 shadow_offsety : 2,  
  40.                 background_color:'#383e46',  
  41.                 tip:{  
  42.                 enable:true,  
  43.                 shadow:true  
  44.                 },  
  45.                 legend:{  
  46.                 enable:true,  
  47.                 background_color : null,  
  48.                 align:'center',  
  49.                 valign:'bottom',  
  50.                 row:1,  
  51.                 column:'max',  
  52.                 color:'#f7f7f7',  
  53.                 legend_space:40,  
  54.                 sign_size:20,  
  55.                 offsety:20,  
  56.                 border : {  
  57.                     enable : false  
  58.                 }  
  59.                },  
  60.                 crosshair:{  
  61.                 enable:true,  
  62.                 line_color:'#62bce9'  
  63.                 },   
  64.                 crosshair:{  
  65.                 enable:true,  
  66.                 line_color:'#62bce9'  
  67.                 },  
  68.                 sub_option : {  
  69.                 label:false,  
  70.                 hollow_inside:false,  
  71.                 point_size:8  
  72.                 },  
  73.                 coordinate:{  
  74.                 width:'82%',  
  75.                 height:'80%',  
  76.                 gridVStyle:{color:'#383e46'},  
  77.                 grid_color:'#cccccc',  
  78.                 axis : {  
  79.                 width : 0  
  80.                 },  
  81.                 grids:{  
  82.                 horizontal:{  
  83.                 way:'share_alike',  
  84.                 value:8  
  85.                 },  
  86.                 vertical: {  
  87.                  way:'share_alike',   
  88.                  value:1   
  89.                  }   
  90.                   
  91.                 },  
  92.                 scale:[{  
  93.                 position:'left',  
  94.                 start_scale:0.7,  
  95.                 end_scale:1.5,  
  96.                 scale_space:0.1,  
  97.                 scale_size:2,  
  98.                 scale_enable:false,  
  99.                 label : {color:'#ffffff',fontsize:12},  
  100.                 scale_color:'#9f9f9f'  
  101.                 },{  
  102.                 position:'bottom',  
  103.                 label : {color:'#ffffff',fontsize:12},  
  104.                 labels:labels  
  105.                 }]  
  106.                 }  
  107.                 });  
  108.                 //开始画图  
  109.                 chart.draw();  
  110.                 });  
  111.   
  112.   </script>  
  113.   </head>  
  114.     
  115.   <body>  
  116.   <div id="canvasDiv"></div>  
  117.   </body>  
  118. </html>  
  119.   
  120. <pre class="html" name="code"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  121. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  122. <html>  
  123.   <head>  
  124.     <script type="text/javascript" src="ichart.1.2.min.js"></script>  
  125.     <script type="text/javascript">  
  126.   
  127.     $(function(){  
  128.         var data = [  
  129.             {  
  130.                 name : '招标采购额占比',  
  131.                 value:[83,86,85,78,91,81,59,82,84,65],  
  132.                 color:'#4f81bd'  
  133.             },  
  134.             {  
  135.                 name : '非招标采购额占比',  
  136.                 value:[17,14,15,22,9,19,41,18,16,35],  
  137.                 color:'#e0b645'  
  138.             },  
  139.             {  
  140.                 name :'常规招标采购比例',  
  141.                 value:[],  
  142.                 color :'#f7f7f7'  
  143.             }  
  144.         ];  
  145.         var chart = new iChart.ColumnStacked2D({  
  146.         render : 'canvasDiv',  
  147.         data: data,  
  148.         labels:["2013年1月","2013年2月","2013年3月","2013年4月","2013年5月","2013年6月","2013年7月","2013年8月","2013年9月","2013年10月"],  
  149.         title : {  
  150.             text:'招标采购比例',  
  151.             color:'#f7f7f7'  
  152.         },  
  153.         align:'center',  
  154.         width : 1000,  
  155.         height : 500,  
  156.         background_color :'#383e46',  
  157.         shadow : true,  
  158.         shadow_blur : 3,  
  159.         shadow_color : '#aaaaaa',  
  160.         shadow_offsetx : 1,  
  161.         shadow_offsety : 0,  
  162.         label:{color:'#f7f7f7'},  
  163.         legend:{  
  164.             enable:true,  
  165.             background_color : null,  
  166.             align:'center',  
  167.             valign:'bottom',  
  168.             row:1,  
  169.             column:'max',  
  170.             color:'#f7f7f7',  
  171.             legend_space:30,  
  172.             offsetx:-90,  
  173.             offsety:10,  
  174.             sign_size:12,  
  175.             border : {  
  176.                 enable : false  
  177.             }  
  178.         },  
  179.         tip:{  
  180.         enable :true,  
  181.         listeners:{  
  182.             //tip:提示框对象、name:数据名称、value:数据值、text:当前文本、i:数据点的索引  
  183.             parseText:function(tip,name,value,text,i){  
  184.             return name+":"+value;  
  185.             }  
  186.           }  
  187.         },  
  188.         percent:true,//标志为百分比堆积图  
  189.         showpercent:true,  
  190.         text_space : 1,//坐标系下方的label距离坐标系的距离。  
  191.         zScale:8,  
  192.         xAngle : 50,  
  193.         sub_option:{  
  194.            label :false  
  195.         },   
  196.         bottom_scale:1.1,  
  197.         coordinate:{  
  198.             width:'82%',  
  199.             height:'80%',  
  200.             board_deep:10,//背面厚度  
  201.             pedestal:false,  
  202.             left_board:false,//取消左侧面板  
  203.             shadow:false,//底座的阴影效果  
  204.             grid_color:'#6a6a80',//网格线  
  205.             axis : {  
  206.                 width : 0  
  207.             },  
  208.             scale:[{  
  209.                 position:'left',  
  210.                 scale_enable : false,  
  211.                 start_scale:0,  
  212.                 scale_space:50,  
  213.                 label:{color:'#f7f7f7'}  
  214.             }]  
  215.         }  
  216.         });  
  217.             var data1 = [  
  218.                 {  
  219.                 name : '常规招标采购比例',  
  220.                 value:[80,80,80,80,80,80,80,80,80,80],  
  221.                 color:'#f7f7f7',  
  222.                 line_width:4  
  223.                 }  
  224.             ];  
  225.         var line = new iChart.LineBasic2D({  
  226.             z_index:1000,  
  227.             data: data1,  
  228.             tip:{  
  229.                 enable :true,  
  230.                 listeners:{  
  231.                 //tip:提示框对象、name:数据名称、value:数据值、text:当前文本、i:数据点的索引  
  232.                 parseText:function(tip,name,value,text,i){  
  233.                 return name+":"+value;  
  234.                }  
  235.               }  
  236.             },  
  237.             sub_option : {  
  238.             smooth:true,  
  239.             label:false,  
  240.           
  241.             hollow_inside:false,  
  242.             point_size:10  
  243.             },  
  244.             intersection:false,  
  245.             coordinate:chart.coo  
  246.             });  
  247.             chart.plugin(line);  
  248.         chart.draw();  
  249.         });  
  250.   
  251.   
  252.   </script>  
  253.   </head>  
  254.     
  255.   <body>  
  256.   <div id="canvasDiv"></div>  
  257.   </body>  
  258. </html>  
  259. </pre><br>  
  260. <pre></pre>  
  261. <p> </p>  
  262. <p><span style="font-size:18px; color:#000000">               效果:<img alt="" src="https://img-blog.csdn.net/20131113141837546?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWlucmFuZXI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center"><img alt="" src="https://img-blog.csdn.net/20131113141851859?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWlucmFuZXI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center"></span></p>  
  263. <pre></pre>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值