Class SVGGenerator
java.lang.Object
com.vaadin.flow.component.charts.export.SVGGenerator
- All Implemented Interfaces:
AutoCloseable
Use instances of this class to generate SVG strings from chart
Configuration instances. 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
ConstructorsConstructorDescriptionCreates a new instance ofSVGGeneratorwhich allocates resources used to transform aConfigurationobject to an SVG string. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()generate(com.vaadin.flow.component.charts.model.Configuration chartConfiguration) Generate an SVG string that can be used to render a chart with data from aConfigurationinstance.generate(com.vaadin.flow.component.charts.model.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 Details
-
SVGGenerator
Creates 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 Details
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
generate
public String generate(com.vaadin.flow.component.charts.model.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
public String generate(com.vaadin.flow.component.charts.model.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.
-