About javaScript "import". Is this way wrong?

12 views
Skip to first unread message

Yang

unread,
Nov 8, 2008, 11:13:34 PM11/8/08
to plotkit
document.write("<script type='text/javascript' src='./plotkit-0.9.1/
PlotKit/excanvas.js'></script>");
document.write("<script type='text/javascript' src='./plotkit-0.9.1/
PlotKit/SweetCanvas.js'></script>");
document.write("<script type='text/javascript' src='./plotkit-0.9.1/
PlotKit/Canvas.js'></script>");
document.write("<script type='text/javascript' src='./plotkit-0.9.1/
PlotKit/Layout.js'></script>");
document.write("<script type='text/javascript' src='./plotkit-0.9.1/
PlotKit/Base.js'></script>");
document.write("<script type='text/javascript' src='./MochiKit-1.3.1/
lib/MochiKit/MochiKit.js'></script>");


function drawimag(type,data)
{
this.type=type;
this.data = data;
}

drawimag.prototype.drawGraph=function()
{
document.write("<div><canvas id='graphimage' height='300'
width='300'></canvas></div>");
var options = {
"IECanvasHTC": "/plotkit/iecanvas.htc",
"colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()
[0]),
"padding": {
left: 0,
right: 0,
top: 10,
bottom: 30
},
"xTicks": [{
v:0,
label:"zero"
},

{
v:1,
label:"one"
},

{
v:2,
label:"two"
},

{
v:3,
label:"three"
},

{
v:4,
label:"four"
}],
"drawYAxis": false
};
var layout = new PlotKit.Layout(this.type,options);
layout.addDataset("sqrt", this.data);
layout.evaluate();
var canvas = MochiKit.DOM.getElement("graphimage");
var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout);
plotter.render();
}

Per Cederberg

unread,
Nov 17, 2008, 9:48:27 AM11/17/08
to plo...@googlegroups.com
It is better not to use document.write when it can be avoided. Load
scripts by either including them on the page, or by calling a
loadScript() helper:

http://trac.mochikit.com/ticket/258#comment:2

Also, the canvas should be added with the DOM API:s in MochiKit:

MochiKit.DOM.CANVAS();

Cheers,

/Per
Reply all
Reply to author
Forward
0 new messages