It is not too hard. Here is a basic script:
var x_min = 0;
var x_max = 10;
var fun = function(x) { return Math.sin(x); }
var image = Document.RasterImage;
var sx = image.sizeX;
var sy = image.sizeY;
var values = [];
for (var i = 0; i < sx; ++i)
values[i] = fun(i*(x_max-x_min)/(sx-1)+x_min);
var y_min = values[0];
var y_max = values[0];
for (var i = 1; i < sx; ++i)
{
if (values[i] < y_min) y_min = values[i];
if (values[i] > y_max) y_max = values[i];
}
var coords = [];
for (var i = 0; i < sx; ++i)
{
coords[i+i] = i+0.5;
coords[i+i+1] = sy-(values[i]-y_min)/(y_max-y_min)*(sy-1)-0.5;
}
DrawTool.SetFillColor(0, 0, 0, 1);
DrawTool.LINE(Document, 3, "JROUND", "CROUND", coords);
You would probably want to change the first 3 lines. x_min and x_max define the range of values that you are interested in and the 3rd line defines the function that you want to graph.