Name of function (method) |
Code example as to be used with the above example object 'jg' (which is the context of the DIV called "myCanvas") |
General Notes
1.) Numbers passed to these functions must always be integer numbers, rather than decimal point numbers (floating point numbers), characters or strings. For instance, values obtained from formular inputs are always strings, and results from previous JavaScript calculations typically floating point numbers. Use either the predefined parseInt() or the Math.round() JavaScript function to convert data to integer. Example:
jg.setStroke(parseInt(document.MyForm.Linewidth.value));
2.) Consider that co-ordinates lie between pixels, not on them, and that the drawing "pen" hangs beneath and to the right of the path specified by co-ordinates passed to the functions. |
setColor("#HexColor");
Specifies the color of the drawing "pen". Once set, this color will be used by the subsequently called drawing methods until it will be overridden through another call of setColor(). The value must be enclosed in quotation marks, and should be hexadecimal following the pattern "#rrggbb" (as usual with HTML). Color names available in HTML (for instance "maroon") may be used as well. |
jg.setColor("#ff0000");
or with identical result
jg.setColor("red");
|
setStroke(Number);
Specifies the thickness of the drawing "pen" for lines and bounding lines of shapes. Once set, this thickness will be used by the subsequently called drawing methods until it will be overridden through another call of setStroke(). Default line thickness is 1px, as long as .setStroke() has not yet been invoked.
To create dotted lines, setStroke() requires the constant Stroke.DOTTED as argument. Width of dotted lines is always 1 pixel. |
jg.setStroke(3);
or
jg.setStroke(Stroke.DOTTED); |
drawLine(X1, Y1, X2, Y2); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setStroke(2);
jg.setColor("#ff6666");
jg.drawLine(0, 11, 40, 0);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Line from the first to the second pair of coordinates. Line thickness is either 1px or the value most recently specified by .setStroke(). |
jg.drawLine(20,50,453,40); |
drawPolyline(Xpoints, Ypoints); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#55aaaa");
jg.drawPolyLine(new Array(0, 10, 20, 30, 40), new Array(0, 11, 0, 11, 0));
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
A polyline is a series of connected line segments. Xpoints and Ypoints are arrays which specify the x and y coordinates of each point as follows:
var Xpoints = new Array(x1,x2,x3,x4,x5); var YPoints = new Array(y1,y2,y3,y4,y5); Instead of Xpoints and Ypoints you may of course use other names provided these follow the rules for JavaScript variable names.
Line thickness is either 1px or the value most recently specified by .setStroke(). |
var Xpoints = new Array(10,85,93,60); var YPoints = new Array(50,10,105,87); jg.drawPolyline(Xpoints,Ypoints); |
drawRect(X,Y,width,height); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#6666ff");
jg.drawRect(0, 0, 40, 11);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Outline of a rectangle. X and Y give the co-ordinates of the left top corner. Line thickness is either 1px or the value most recently specified by .setStroke(). |
jg.drawRect(20,50,70,140); |
fillRect(X,Y,width,height); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#ffcc66");
jg.fillRect(0, 0, 40, 11);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Filled rectangle. X and Y give the co-ordinates to the left top corner. |
jg.fillRect(20,50,453,40); |
drawPolygon(Xpoints, Ypoints); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#cc66cc");
jg.drawPolygon(new Array(0, 20, 40, 20), new Array(5, 0, 5, 11));
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Polygon. Xpoints and Ypoints are arrays which specify the x and y coordinates of the polygon's corners as follows:
var Xpoints = new Array(x1,x2,x3,x4,x5); var Ypoints = new Array(y1,y2,y3,y4,y5); The polygon will be automatically closed if the first and last points are not identical.
Line thickness is either 1px or the value most recently specified by .setStroke(). |
var Xpoints = new Array(10,85,93,60); var Ypoints = new Array(50,10,105,87); jg.drawPolygon(Xpoints, Ypoints);
Instead of Xpoints and Ypoints you may of course use other names provided these follow the rules for variable names. |
fillPolygon(Xpoints, Ypoints); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#99ccff");
jg.fillPolygon(new Array(0, 20, 40, 20), new Array(6, -1, 6, 13));
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Filled Polygon. Parameters as for drawPolygon() |
jg.fillPolygon(new Array(10,85,93,60), new Array(50,10,105,87)); |
drawEllipse(X,Y,width,height); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#55bb55");
jg.drawOval(0, -1, 40, 12);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Outline of an ellipse. Values refer to the bounding rectangle of the ellipse, X and Y give the co-ordinates of the left top corner of that rectangle rather than of its center. Line thickness is either 1px or the value most recently specified by .setStroke(). |
jg.drawEllipse(20,50,70,140); or
jg.drawOval(20,50,70,140); |
fillEllipse(X,Y,width,height); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:50px;height:13px;"><table cellpadding="0" cellspacing="0"><tr><td>';
jg.setColor("#ffccdd");
jg.fillOval(0, -1, 41, 13);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Filled ellipse. Values refer to the bounding rectangle of the ellipse, X and Y give the co-ordinates of the left top corner of that rectangle rather than of its center. |
jg.fillEllipse(20,50,71,141); or
jg.fillOval(20,50,71,141); |
setFont("font-family", "size+unit", Style);
This method can be invoked prior to drawString() to specify or change font-family, -size and -style. Values or font-family and -size may be whatever possible in HTML, and must be enclosed in quotation marks.
Available font styles: Font.PLAIN for normal style (not bold, not italic) Font.BOLD for bold fonts Font.ITALIC for italics Font.ITALIC_BOLD or Font.BOLD_ITALIC to combine the latters. |
Example: see drawString() below |
drawString("Text", X, Y); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:400px;height:16px;"><table cellpadding="0" cellspacing="0" width="400"><tr><td>';
jg.setFont("arial,helvetica,sans-serif", "15px", Font.ITALIC_BOLD);
jg.setColor("#cc6600");
jg.drawString("I've been drawn with the Vectorgraphics Library...", 0, 0);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
I've been drawn with the Vectorgraphics Library...
|
Writes text to the location specified by X and Y. Differently from Java, these coordinates refer to the left top corner of the first line of the text. The string passed to drawString() must be enclosed in quotation marks. (Non-escaped) HTML tags inside the string will be interpreted. For example, "SomeText<br>moreText" would indeed create a line break. |
jg.setFont("arial","15px",Font.ITALIC_BOLD);
jg.drawString("SomeText",20,50); |
drawStringRect("Text", X, Y, Width, Alignment); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:400px;height:100px;"><table cellpadding="0" cellspacing="0" width="400"><tr><td>';
jg.setFont("verdana,geneva,sans-serif", "11px", Font.BOLD);
jg.setColor("#009999");
jg.drawStringRect("A text drawn by using drawStringRect() which allows to set the width of the text rectangle and to align the text horizontally (in this case "right")", 4, 4, 292, "right");
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
A text drawn by using drawStringRect() which allows to set the width of the text rectangle and to align the text horizontally (in this case "right")
|
Like drawString. Allows however to set the width of the text rectangle and to specify the horizontal text-alignment. Text-alignment value must be a string (i.e. enclosed in quotation marks or apostrophes) and can be either "left", "center", "right" or "justify". |
jg.setFont("verdana","11px",Font.BOLD);
jg.drawStringRect("Text",20,50,300,"right"); |
drawImage("src", X, Y, width, height); <script type="text/javascript">
<!--
jg.htm += '<div style="position:relative;width:400px;height:64px;"><table cellpadding="0" cellspacing="0" width="400"><tr><td>';
jg.drawImage("../images/dragdrop/deddie.jpg", 0, 0, 90, 62);
jg.htm += '<//td><//tr><//table><//div>';
jg.paint();
//-->
</script>
Draws image on the specified location. "src" parameter specifies path, width and height parameters allow to stretch the image (almost) arbitrarily.
Optionally, drawImage() accepts a fifth parameter which you can use to insert an eventhandler into the generated image tag. Example:
jg.drawImage('anImg.jpg',8,5,95,70,'onmouseover="YourFunc()"');
|
jg.drawImage("friendlyDog.jpg", 20,50,100,150); |
paint();
Must be envoked explicitly to draw the internally-generated graphics into the html page. To optimize performance it's recommended to restrain from calling paint() in unnecessarily short intervals.
Avoid something like: jg.drawEllipse(0, 0, 100, 100); jg.paint(); jg.drawLine(200, 10, 400, 40); jg.paint(); ...
The following will be faster: jg.drawEllipse(0, 0, 100, 100); jg.drawLine(200, 10, 400, 40); /*...further drawing methods... */ jg.paint(); |
jg.paint(); |
clear();
Any content created by the Graphics JavaScript Library will be deleted (within the canvas the graphics object refers to). The default content of the canvas (content not created by the script) will remain untouched, i.e. neither be changed nor be deleted. |
jg.clear();
Any stuff within "myCanvas" (in these examples the DIV 'jg' refers to) drawn by the script is deleted. |
setPrintable(true);
By default, printing shapes isn't feasible since default printing settings of browsers usually prevent background colors from being printed. Invoking setPrintable() with the parameter true enables wz_jsgraphics.js to draw printable shapes (at least in Mozilla/Netscape6+ and IE). However, at the price of a slightly decreased rendering speed (about 10% to 25% slower). |
jg.setPrintable(false);
The parameter false switches wz_jsgraphics.js back to non-printable mode. The benefit from this, however, will be re-optimized rendering performance. |
|
相关推荐
DHTML&javascript 使用手册 动态 HTML (DHTML) 对象模型参考 DHTML 对象 DHTML 属性 DHTML 方法 DHTML 事件 DHTML 集合 HTML 参考 HTML 元素 HTML 字符集 样式表(CSS)参考 CSS 属性参考 CSS 长度单位参考...
通过JavaScript操作canvas元素的API,开发者可以直接在画布上绘制路径、矩形、圆形等矢量图形,还可以实现图像的动态更新和动画效果。 - **SVG**:SVG是一种基于XML的矢量图形格式,与VML相比,SVG得到了更广泛的...
**VML网页矢量图** VML(Vector Markup Language)是用于在网页上绘制矢量图形的一种技术。DHTML手册可能会介绍如何创建、操作和动画化VML图形,以及如何与其他DHTML元素结合使用。 **命令标识符** 命令标识符...
HTML5是目前最新的版本,引入了许多新特性,如离线存储、音频/视频元素、Canvas画布、SVG矢量图以及新的表单控件等,极大地丰富了网页的展示效果和功能。 **DHTML:动态HTML** DHTML是在HTML基础上加入CSS...
1. **CSS**:负责网页的样式和布局,DHTML利用CSS实现了元素的动态定位和动画效果。 2. **DOM**:是HTML和XML文档的结构化表示,JavaScript可以通过DOM操作网页元素,实现动态更新内容。 3. **JavaScript**:提供了...
HTML5引入了许多新特性,如音频、视频、 canvas画布、SVG矢量图等,这些都为DHTML提供了更多动态元素的可能性。 **2. CSS参考** CSS用于控制网页的外观和布局,包括字体、颜色、布局、动画效果等。在DHTML中,CSS...
JVGL完全基于DHTML和JavaScript技术实现。DHTML是传统HTML的动态扩展,在JavaScript或VBScript的基础上提供了一个扩展的文档对象模型DOM,并允许在数据流关闭之后,由JavaScript或VBScript代碼来动态地改变Web页面的...
DHTML(Dynamic HTML),动态HTML,是HTML的一种增强技术,它结合了HTML、CSS、JavaScript以及DOM(Document Object Model)等元素,使得网页内容能够实现动态交互和更新,无需页面刷新。本手册详细介绍了DHTML在...
4. **HTML5新特性**:DHTML也包括HTML5的新元素和API,如Canvas绘图、SVG矢量图、WebSocket实时通信等。 **CSS3.0参考手册** CSS3是CSS的最新版本,引入了许多新特性和增强。`css3.0参考手册.chm`可能包含: 1. *...
综上所述,DHTML参考手册是理解并应用这些技术的宝贵资源,它涵盖了从基础概念到高级技巧的各个方面,对于希望深入学习和使用DHTML的开发者来说非常有价值。尽管现代Web开发中已有了更多的选择,如React、Vue等框架...
JavaScript中文手册是一本详尽的资源,旨在帮助中文使用者深入理解和掌握JavaScript这门编程语言。JavaScript,有时简称为JS,是互联网上最广泛使用的客户端脚本语言,它主要用于增强网页的交互性和动态功能。这份...
SVG则是矢量图格式,支持高质量的图形和图像处理。 5. **Geolocation API**:HTML5提供了获取用户地理位置的能力,为地理位置相关的应用提供了便利。 6. **Web Workers和Web Storage**:Web Workers允许在后台执行...
Web 开发常用手册! 1 动态 HTML (DHTML) 对象模型参考 DHTML 对象 DHTML 属性 DHTML 方法 DHTML 事件 ...可视化滤镜和切换参考 HTML+TIME参考 网页矢量图形标记语言 HTML 应用程序 技巧 语言代码 颜色表
1. **DHTML**:DHTML是一种结合HTML、CSS、JavaScript和DOM(文档对象模型)的技术,用于创建交互式和动态的网页内容。它允许网页在不重新加载整个页面的情况下改变内容、样式和结构,实现如下拉菜单、滑动效果、...
YUI 工具包利用 DOM 脚本来简化浏览器内的开发(in-browser devolvement),使用 DHTML 和 AJAX 的特性开发所有的 Web 程序。YUI 控件库为您提供了一组高交互性性的可视化元素,这些元素完全在客户端创建维护,不...
在网页开发领域,DHTML(Dynamic HTML)是一种用于创建交互式和动态网页的技术,它结合了HTML、CSS、JavaScript以及DOM(Document Object Model)来实现页面的动态效果。这份"DHTML标记大全、API文档"是网页开发者不...
网页制作完全手册 ...可视化滤镜和切换参考 HTML+TIME参考 网页矢量图形标记语言 HTML 应用程序 技巧 语言代码 颜色表 --------------------------------------------------------------------------------
- **Canvas** 和 **SVG**:提供图形绘制和矢量图像的能力。 **3. CSS(层叠样式表)** CSS负责网页的样式和布局,它与HTML分离,使页面设计更加灵活。关键概念包括: - **选择器**:如类选择器(`.class`)、ID...
至于“VML网页矢量图”,Vector Markup Language(VML)是一种用于在网页上显示矢量图形的标准,特别是在Internet Explorer较旧版本中广泛使用。尽管SVG(Scalable Vector Graphics)现在更被推崇,但理解VML对于...
资源中的那个无法下载,在网上找了一个,传上来,分享! 通过下列链接访问参考资料,可帮助你创建引人注目的 Web...可视化滤镜和切换参考 HTML+TIME参考 网页矢量图形标记语言 HTML 应用程序 技巧 语言代码 颜色表