Generate an empty grid

final String svg = new SvgGraph().generate();
1 0 0 1

Specify grid size

final String svg = new SvgGraph()
        .withHeight(100)
        .withWidth(200)
        .generate();
1 0 0 1

Draw a single line

final String svg = new SvgGraph()
        .withLine("Values", Arrays.asList(0, 20, 10))
        .generate();
20 0 0 2

Draw a single line with negative values

final String svg = new SvgGraph()
        .withLine("Values", Arrays.asList(0, -20, -10))
        .generate();
0 -20 0 2

Draw a single line with negative and positive values

final String svg = new SvgGraph()
        .withLine("Values", Arrays.asList(-15, 4, -6, 30, 25))
        .generate();
30 -15 0 4

Draw a single line with float values

final String svg = new SvgGraph()
        .withLine("Values", Arrays.asList(-2.5, 1.2, -0.5, 3.6))
        .generate();
4 -3 0 3

Draw several lines

final String svg = new SvgGraph()
        .withLine("Line A", Arrays.asList(-15, 6, 30, 25))
        .withLine("Line B", Arrays.asList(5, 12, 45, 17))
        .withLine("Line C", Arrays.asList(-5, -10, -20, 8))
        .generate();
45 -20 0 3

Apply factor on axes

By default, the factor apply for axis is calculated to fill the space. This factor could be set manually. It can be use to display several graph with the same scale.

final String svg = new SvgGraph()
        .withXFactor(290) // 580 / 2 => grid width / nb values
        .withYFactor(10) // 380 / 38 => grid height / max value
        .withLine("Values", Arrays.asList(10, 38, 20)).generate();
38 0 0 2

Here, with a max value at 38 and a factor at 4, the max point is 38 * 4 = 152 This point is only 8 pixels below the height of the grid specified (160).

final String svg = new SvgGraph()
        .withHeight(160)
        .withYFactor(4)
        .withLine("Values", Arrays.asList(10, 38, 20)).generate();
38 0 0 2