Generate an empty grid
final String svg = new SvgGraph().generate();
Specify grid size
final String svg = new SvgGraph()
.withHeight(100)
.withWidth(200)
.generate();
Draw a single line
final String svg = new SvgGraph()
.withLine("Values", Arrays.asList(0, 20, 10))
.generate();
Draw a single line with negative values
final String svg = new SvgGraph()
.withLine("Values", Arrays.asList(0, -20, -10))
.generate();
Draw a single line with negative and positive values
final String svg = new SvgGraph()
.withLine("Values", Arrays.asList(-15, 4, -6, 30, 25))
.generate();
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();
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();
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();
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();