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.指定绘图颜色的“笔”。一旦设置,将使用此颜色由所谓的绘图方法,直到后来便)重写通过另一个调用setColor(。值必须用引号,应该十六进制下面的模式“#rrggbb”(通常为HTML的)。颜色名称在HTML中可用(例如为“栗色”)可作为良好。 |
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 1?px, as long as .setStroke() has not yet been invoked.指定绘图厚度的“笔”形状的线条和边界线。一旦设置,这个厚度将在其后所使用的方法称为图纸,直到将覆盖厚度通过另一个电话setStroke()。默认是1像素线,只要。setStroke()尚未被调用。 To create dotted lines, setStroke() requires the constant Stroke.DOTTED as argument. Width of dotted lines is always 1 pixel.要创建虚线,setStroke()需要不断的争论Stroke.DOTTED作为。线条宽度的点永远是1像素。 |
jg.setStroke(3); or或 jg.setStroke(Stroke.DOTTED); |
|
drawLine( X1, Y1, X2, Y2 ); <script type="text/javascript"></script>
|
jg.drawLine(20,50,453,40); |
|
drawPolyline( Xpoints, Ypoints ); <script type="text/javascript"></script>
var Xpoints = new Array(x1,x2,x3,x4,x5); Instead of Xpoints and Ypoints you may of course use other names provided these follow the rules for JavaScript variable names.而不是Xpoints和Ypoints你当然可以使用其他名称提供这些后续的JavaScript变量名的规则。 Line thickness is either 1px or the value most recently specified by .setStroke() .要么是1px线厚度值或最近指定。setStroke()。 |
var Xpoints = new Array(10,85,93,60); |
|
drawRect( X,?Y,?width,?height ); <script type="text/javascript"></script>
|
jg.drawRect(20,50,70,140); |
|
fillRect( X,?Y,?width,?height ); <script type="text/javascript"></script>
|
jg.fillRect(20,50,453,40); |
|
drawPolygon( Xpoints, Ypoints ); <script type="text/javascript"></script>
var Xpoints = new Array(x1,x2,x3,x4,x5); 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() .要么是1px线厚度值或最近指定。setStroke()。 |
var Xpoints = new Array(10,85,93,60); Instead of Xpoints and Ypoints you may of course use other names provided these follow the rules for variable names.而不是Xpoints和Ypoints你当然可以使用其他名称为提供这些后续变量名的规则。 |
|
fillPolygon( Xpoints, Ypoints ); <script type="text/javascript"></script>
|
jg.fillPolygon(new Array(10,85,93,60), new Array(50,10,105,87)); jg.fillPolygon(new Array(10,85,93,60), new Array(50,10,105,87)); |
|
drawEllipse( X,?Y,?width,?height ); <script type="text/javascript"></script>
|
jg.drawEllipse(20,50,70,140); or或 jg.drawOval(20,50,70,140); |
|
fillEllipse( X,?Y,?width,?height ); <script type="text/javascript"></script>
|
jg.fillEllipse(20,50,71,141); or或 jg.fillOval(20,50,71,141); |
|
fillArc( X,?Y,?width,?height,?start-angle,?end-angle ); <script type="text/javascript"></script>
|
jg.fillArc(20,20,41,12,270.0,220.0); |
|
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.PLAIN不) Font.BOLD for bold fonts Font.BOLD大胆的字体 Font.ITALIC for italics Font.ITALIC为斜体 Font.ITALIC_BOLD or Font.BOLD_ITALIC to combine the latters. Font.ITALIC_BOLD或Font.BOLD_ITALIC合并后者。 |
Example: see drawString() below例如:见drawString() 以下 |
|
drawString( "Text", X, Y ); <script type="text/javascript"></script>
|
jg.setFont("arial","15px",Font.ITALIC_BOLD); jg.drawString("Some?Text",20,50); |
|
drawStringRect( "Text", X, Y, Width, Alignment ); <script type="text/javascript"></script> |
jg.setFont("verdana","11px",Font.BOLD); jg.drawStringRect("Text",20,50,300,"right"); |
|
drawImage( "src", X, Y, width, height ); <script type="text/javascript"></script> Optionally, drawImage() accepts a fifth parameter which you can use to insert an eventhandler into the generated image tag. Example:或者,drawImage()接受了第五个参数,你可以用它来插入。示例一个EventHandler到生成的图片标记: jg.drawImage('anImg.jpg',8,5,95,70,'onmouseover="YourFunc()"'); |
jg.drawImage("friendlyDog.jpg", 20,50,100,150); 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.必须envoked明确地绘制图形到HTML页的内部产生。为了优化性能,它的建议,以制止不必要的电话很短的间隔漆(以上)。 Avoid something like:避免类似: jg.drawEllipse(0, 0, 100, 100); jg.drawEllipse(1,0,100,100); jg.paint(); jg.paint(); jg.drawLine(200, 10, 400, 40); jg.drawLine(200,10,400,40); jg.paint(); jg.paint(); ... ... The following will be faster:下面会更快: jg.drawEllipse(0, 0, 100, 100); jg.drawEllipse(1,0,100,100); jg.drawLine(200, 10, 400, 40); jg.drawLine(200,10,400,40); /*...further drawing methods... /*...进一步绘图方法... */ * / jg.paint(); 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, ie neither be changed nor be deleted. JavaScript的库的图形创建的任何内容将被删除画布(图形对象内指)。默认的画布上的内容(脚本内容并非由)将维持原状,即不得更改或删除。 |
jg.clear(); Any stuff the script has drawn to "myCanvas" is deleted (assuming that "myCanvas" is the DIV for which 'jg' has been created).任何东西的脚本已经制定的“myCanvas”是删除(假设“myCanvas”是其中的DIV为'约格森米'已被创建)。 |
|
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/Netscape?6+ and IE). However, at the price of a slightly decreased rendering speed (about 10% to 25% slower).默认情况下,印刷可行的形状不是浏览器默认的打印设置的,因为通常防止背景色被打印出来。调用setPrintable()与参数真正使wz_jsgraphics.js提请至少在打印形状(Mozilla / Netscape中和IE 6 + )。然而,在价格略有下降绘制速度(约10%至25%速度较慢)。 |
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.虚假的参数开关wz_jsgraphics.js回非打印模式。这得益于然而,将重新优化渲染性能。 |
?
?
简化的画线方法
<script>
function line(s_x,s_y,e_x,e_y,rate)
{
var k=(s_y-e_y)/(s_x-e_x);
for (i=0;i<=Math.abs(s_x-e_x);i=i+rate)
{
x=s_x+i;
y=s_y+i*k;
document.write("<div style='position:absolute;width:1;height:1;left:"+x+";top:"+y+";'><font color=red>.</font></div>");
}
}
line(100,100,200,200,1);
</script>