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 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

    Constructors
    Constructor
    Description
    Creates a new instance of SVGGenerator which allocates resources used to transform a Configuration object to an SVG string.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    generate(com.vaadin.flow.component.charts.model.Configuration chartConfiguration)
    Generate an SVG string that can be used to render a chart with data from a Configuration instance.
    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 a Configuration instance.
    boolean
    Check if this generator is closed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SVGGenerator

      public SVGGenerator() throws IOException

      Creates a new instance of SVGGenerator which allocates resources used to transform a Configuration object to an SVG string.

      You must close the generator when you're done using it. Use a try-with-resources block or call the close() method.

      Throws:
      IOException - if there's any issue allocating resources needed.
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      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 a Configuration instance.
      Parameters:
      chartConfiguration - the Configuration with the chart's data.
      Returns:
      an SVG string resulting from the Configuration.
      Throws:
      NullPointerException - when passing a null configuration.
      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 a Configuration instance.
      Parameters:
      chartConfiguration - the Configuration with the chart's data.
      exportOptions - optional exporting options to customize the result.
      Returns:
      an SVG string resulting from the Configuration, customized as per the ExportOptions.
      Throws:
      NullPointerException - when passing a null configuration.
      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:
      true if the generator is closed, false otherwise.