Vaadin Sparkline is a standalone sparkline component for Vaadin Flow

Vaadin Sparkline is a standalone sparkline component for Vaadin Flow. See also Grid Sparkline renderer: https://vaadin.com/directory/component/grid-sparklinerenderer-flow

Basic use

public class SparklineTest extends VerticalLayout {

    public SparklineTest() {
        //...
        Sparkline sparklineSimple = new Sparkline(createSparklineValues(createSong()));
        sparklineSimple.setWidth("120px");
        sparklineSimple.setHeight("20px");
        add(sparklineSimple);
        //...
    }

    private SparklineValues createSparklineValues(Song song) {
        // convert existing time series data to a SparklineValues object
        return new SparklineValues(song.getDailyListeners().getMeasurements().stream()
                     .map(measurement -> new SparklineValues.SparklineValue(
                               measurement.getInstant(), measurement.getValue())).collect(Collectors.toList()));
    }
}

With Plot bands

public class SparklineTest extends VerticalLayout {
    
    private void plotBandDemo() {
        //... 
        Patient patient = createPatient();
        Sparkline sparklinePlotBands = new Sparkline(createSparklineValuesTemp(patient), 
                          createSparklineConfTemp(patient));
        sparklinePlotBands.setWidth("120px");
        sparklinePlotBands.setHeight("20px");
        add(sparklinePlotBands);
    }
    
    private SparklineConfiguration createSparklineConfTemp(Patient patient) {
            return new SparklineConfiguration()
                    // scale y-axis between min and ax value
                    .withAutoScaleYAxis(true)
                    // add a plotband with line color and background color
                    .withPlotBand(new SparkLinePlotBand(36.0, 38.0)
                    .withBackgroundColor(SparklineConfiguration.LIGHT_GREEN)
                    .withLineColor(Color.GREEN))
                    // add a plotband with line color
                    .withPlotBand(new SparkLinePlotBand(38.0, 41.0)
                            .withLineColor(Color.RED));
    }
}

License & Author

This Add-on is distributed under Apache 2.0

Component Factory Sparkline is written by Vaadin Ltd.

Sponsored development

Major pieces of development of this add-on has been sponsored by multiple customers of Vaadin. Read more about Expert on Demand at: Support and Pricing

Install

Link to this version
BetaReleased 11 December 2020Apache License 2.0
Framework Support
Vaadin platform 14
Browser Compatibility
Install with
Release notes - Version 2.0.0
  • Update the license to Apache 2.0
  • Update to Vaadin 14.
  • Change package name from com.vaadin.flow.component to com.vaadin.componentfactory