lichartee/doc/tutorials.md
2024-01-01 23:15:58 +01:00

1.6 KiB

Tutorials

Quick start guide

This tutorial covers some basic usage to help getting started with lichartee.

A Simple example

Display of a five-point dotted red trace of the square function on a canvas at the end of a web page.

let manager = new Manager(
    document.getElementsByTagName('body')[0],
);
manager.add_canvas(500, 500).figure.add_axes().plot(
    [0, 1, 2, 3, 4 , 5 ],
    [0, 1, 4, 9, 16, 25],
    {
        color: 'red'   ,
        style: 'dashed',
    }                   ,
);
manager.draw();

The first instruction create a Manager which can be used to manage one or more Canvas. This manager is defined from the html <body> tag, so each Canvas managed by this one will be at the end of this elements.

The second instruction do a lot of things at once. First, the method add_canvas add, like this name indicate, a Canvas with a specific width and height associated to the Manager we created before. Next, the method add_axes of the figure property of the canvas we created add an Axes to this figure. Then, the plot method take the first list of number as the x coordinate of points, the second as y ones and finally, an optional dictionary which define the style of the plot composed of each point.

Finally the draw method render the plot we created to display it on the created canvas in the web page.