Class SVGGenerator
- java.lang.Object
-
- com.vaadin.flow.component.charts.export.SVGGenerator
-
- All Implemented Interfaces:
AutoCloseable
public class SVGGenerator extends Object implements AutoCloseable
Use instances of this class to generate SVG strings from chart
Configurationinstances. You must close the generator when you're done with it. You can use a try-with-resources block to close it automatically. You must have NodeJS installed for this to work.
CSS styling is not supported.
Example usage:
Configuration configuration = new Configuration(); // ... try (SVGGenerator generator = new SVGGenerator()) { String svg = generator.generate(configuration); }- Since:
- 21.0
-
-
Constructor Summary
Constructors Constructor Description SVGGenerator()Creates a new instance ofSVGGeneratorwhich allocates resources used to transform aConfigurationobject to an SVG string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Stringgenerate(Configuration chartConfiguration)Generate an SVG string that can be used to render a chart with data from aConfigurationinstance.Stringgenerate(Configuration chartConfiguration, ExportOptions exportOptions)Generate an SVG string that can be used to render a chart with data from aConfigurationinstance.booleanisClosed()Check if this generator is closed.
-
-
-
Constructor Detail
-
SVGGenerator
public SVGGenerator() throws IOExceptionCreates a new instance of
SVGGeneratorwhich allocates resources used to transform aConfigurationobject to an SVG string.You must close the generator when you're done using it. Use a
try-with-resourcesblock or call theclose()method.- Throws:
IOException- if there's any issue allocating resources needed.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
generate
public String generate(Configuration chartConfiguration) throws IOException, InterruptedException
Generate an SVG string that can be used to render a chart with data from aConfigurationinstance.- Parameters:
chartConfiguration- theConfigurationwith the chart's data.- Returns:
- an SVG string resulting from the
Configuration. - Throws:
NullPointerException- when passing anullconfiguration.IllegalStateException- when called on a closed generator.IOException- if anything happens using or allocating resources to virtually render the chart.InterruptedException- if the rendering process gets interrupted.- See Also:
generate(Configuration, ExportOptions)
-
generate
public String generate(Configuration chartConfiguration, ExportOptions exportOptions) throws IOException, InterruptedException
Generate an SVG string that can be used to render a chart with data from aConfigurationinstance.- Parameters:
chartConfiguration- theConfigurationwith the chart's data.exportOptions- optional exporting options to customize the result.- Returns:
- an SVG string resulting from the
Configuration, customized as per theExportOptions. - Throws:
NullPointerException- when passing anullconfiguration.IllegalStateException- when called on a closed generator.IOException- if anything happens using or allocating resources to virtually render the chart.InterruptedException- if the rendering process gets interrupted.
-
isClosed
public boolean isClosed()
Check if this generator is closed.
- Returns:
trueif the generator is closed,falseotherwise.
-
-