设为首页收藏本站

birt家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3318|回复: 1

RGraph 官方图表示例(十三)仪表盘

[复制链接]
发表于 2012-8-9 09:56:32 | 显示全部楼层 |阅读模式
这是RGraph 官方的仪表盘示例
效果如下:

代码如下:
  1. <%@ include file="/common/tags.jsp"%>
  2. <%@ page contentType="text/html; charset=utf-8"%>
  3. <!DOCTYPE html>
  4. <html>
  5.     <head>
  6.         <title>RGraph: An example of the Meter chart</title>
  7.         <meta name="keywords" content="rgraph html5 canvas example meter charts" />
  8.         <meta name="description" content="An example of the Meter chart that RGraph can produce" />
  9.         <meta name="googlebot" content="NOODP">
  10.         <meta property="og:title" content="RGraph: HTML5 Javascript charts library" />
  11.         <meta property="og:description" content="A charts library based on the HTML5 canvas tag" />
  12.         <meta property="og:image" content="http://www.rgraph.net/images/logo.png"/>
  13.         <link rel="stylesheet" href="${ctx}/script/html5/rgraph/css/website.css" type="text/css" media="screen" />
  14.         <link rel="icon" type="image/png" href="${ctx}/script/html5/rgraph/images/favicon.png">
  15.         <!-- Place this tag in your head or just before your close body tag -->
  16.         <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
  17.         <script src="${ctx}/script/html5/rgraph/libraries/RGraph.common.core.js" ></script>
  18.         <script src="${ctx}/script/html5/rgraph/libraries/RGraph.common.effects.js" ></script>
  19.         <script src="${ctx}/script/html5/rgraph/libraries/RGraph.meter.js" ></script>
  20.         <!--[if lt IE 9]><script src="${ctx}/script/html5/rgraph/excanvas/excanvas.original.js"></script><![endif]-->
  21.         <script>
  22.             $(function(){
  23.                 _createChart();
  24.             });
  25.             /**
  26.              * 仪表盘
  27.              */
  28.             function _createChart(){
  29.                 var min = 0;
  30.                 var max = 100;
  31.                 var meter1 = new RGraph.Meter('meter1', min, max, 74);
  32.                 var grad1 = meter1.context.createRadialGradient(meter1.canvas.width / 2,meter1.canvas.height - 25,0,meter1.canvas.width / 2,meter1.canvas.height - 25,200);
  33.                 grad1.addColorStop(0, 'green');
  34.                 grad1.addColorStop(1, 'white');
  35.                 var grad2 = meter1.context.createRadialGradient(meter1.canvas.width / 2, meter1.canvas.height - 25,0,meter1.canvas.width / 2, meter1.canvas.height - 25,200);
  36.                 grad2.addColorStop(0, 'yellow');
  37.                 grad2.addColorStop(1, 'white');
  38.                 var grad3 = meter1.context.createRadialGradient(meter1.canvas.width / 2, meter1.canvas.height - 25,0,meter1.canvas.width / 2, meter1.canvas.height - 25,200);
  39.                 grad3.addColorStop(0, 'red');
  40.                 grad3.addColorStop(1, 'white');
  41.                 meter1.Set('chart.labels.position', 'inside');
  42.                 meter1.Set('chart.title', 'A sample measurement (adjustable)');
  43.                 meter1.Set('chart.title.vpos', 0.5);
  44.                 meter1.Set('chart.title.color', 'black');
  45.                 meter1.Set('chart.green.color', grad1);
  46.                 meter1.Set('chart.yellow.color', grad2);
  47.                 meter1.Set('chart.red.color', grad3);
  48.                 meter1.Set('chart.border', false);
  49.                 meter1.Set('chart.needle.linewidth', 5);
  50.                 meter1.Set('chart.needle.tail', true);
  51.                 meter1.Set('chart.tickmarks.big.num', 0);
  52.                 meter1.Set('chart.tickmarks.small.num', 0);
  53.                 meter1.Set('chart.segment.radius.start', 100);
  54.                 meter1.Set('chart.needle.radius', 80);
  55.                 meter1.Set('chart.needle.linewidth', 2);
  56.                 meter1.Set('chart.linewidth.segments', 15);
  57.                 meter1.Set('chart.strokestyle', 'white');
  58.                 meter1.Set('chart.text.size', 14);
  59.                 meter1.Draw();
  60.                 meter1.canvas.onmousedown = function (e)
  61.                 {
  62.                     var obj   = e.target.__object__;
  63.                     var value = obj.getValue(e);
  64.                     obj.value = value;
  65.                     RGraph.Effects.Meter.Grow(obj);
  66.                 }
  67.             }
  68.         </script>
  69.     </head>
  70.     <body>
  71.         <script>
  72.             if (RGraph.isOld()) {
  73.                 document.write('<div style="background-color: #fee; border: 2px dashed red; padding: 5px"><b>Important</b><br /><br /> Internet Explorer does not natively support the HTML5 canvas tag, so if you want to see the charts, you can either:<ul><li>Install <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a></li><li>Use ExCanvas. This is provided in the RGraph Archive.</li><li>Use another browser entirely. Your choices are Firefox 3.5+, Chrome 2+, Safari 4+ or Opera 10.5+. </li></ul> <b>Note:</b> Internet Explorer 9 fully supports the canvas tag.</div>');
  74.             }
  75.         </script>
  76.         <div style="text-align: center">
  77.             <canvas id="meter1" width="400" height="250"><div class="canvasfallback">[No canvas support]</div></canvas>
  78.         </div>
  79.     </div>
  80. </body>
  81. </html>
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
 楼主| 发表于 2012-8-9 09:57:12 | 显示全部楼层
效果其实挺不错的,就是展现速度有些慢,这个估计要优化一下。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|birt家园    

GMT+8, 2020-8-7 16:55 , Processed in 0.249750 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表