Search in sources :

Example 51 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class SplineUpdatingEachSecond method initDemo.

@Override
public void initDemo() {
    // NOSONAR
    final Random random = new Random();
    final Chart chart = new Chart();
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Live random data");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setType(AxisType.DATETIME);
    xAxis.setTickPixelInterval(150);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    configuration.getTooltip().setEnabled(false);
    configuration.getLegend().setEnabled(false);
    final DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
    }
    configuration.setSeries(series);
    runWhileAttached(chart, () -> {
        final long x = System.currentTimeMillis();
        final double y = random.nextDouble();
        series.add(new DataSeriesItem(x, y), true, true);
    }, 1000, 1000);
    add(chart);
}
Also used : Random(java.util.Random) Configuration(com.vaadin.flow.component.charts.model.Configuration) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotOptionsSpline(com.vaadin.flow.component.charts.model.PlotOptionsSpline) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 52 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class Bullet method createBulletChart.

/**
 * Create a bullet chart with shared configuration
 *
 * @param plotBandY1
 *            "from" value for the first plotband
 * @param plotBandY2
 *            "to" value for the first plotband and "from" value for the
 *            second plotband
 * @param plotBandY3
 *            "to" value for the second plotband and "from" value for the
 *            third plotband
 * @param plotBandY4
 *            "to" value for the third plotband
 * @param y
 *            Y value for the series item
 * @param target
 *            Target value for the series item
 * @param category
 *            Title to be used in the category
 * @return Chart with shared configuration
 */
private Chart createBulletChart(Number plotBandY1, Number plotBandY2, Number plotBandY3, Number plotBandY4, Number y, Number target, String category) {
    Chart chart = new Chart(ChartType.BULLET);
    chart.setHeight("85px");
    Configuration conf = chart.getConfiguration();
    conf.getChart().setInverted(true);
    conf.getChart().setMarginLeft(135);
    conf.getLegend().setEnabled(false);
    YAxis yAxis = conf.getyAxis();
    yAxis.setGridLineWidth(0);
    yAxis.setTitle("");
    yAxis.addPlotBand(new PlotBand(plotBandY1, plotBandY2, new SolidColor("#666666")));
    yAxis.addPlotBand(new PlotBand(plotBandY2, plotBandY3, new SolidColor("#999999")));
    yAxis.addPlotBand(new PlotBand(plotBandY3, plotBandY4, new SolidColor("#bbbbbb")));
    conf.getxAxis().addCategory(category);
    conf.getTooltip().setPointFormat("<b>{point.y}</b> (with target at {point.target})");
    PlotOptionsBullet options = new PlotOptionsBullet();
    options.setPointPadding(0.25);
    options.setBorderWidth(0);
    options.setColor(SolidColor.BLACK);
    options.getTargetOptions().setWidth("200%");
    conf.setExporting(false);
    DataSeries series = new DataSeries();
    series.add(new DataSeriesItemBullet(y, target));
    series.setPlotOptions(options);
    conf.addSeries(series);
    return chart;
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) SolidColor(com.vaadin.flow.component.charts.model.style.SolidColor) PlotOptionsBullet(com.vaadin.flow.component.charts.model.PlotOptionsBullet) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotBand(com.vaadin.flow.component.charts.model.PlotBand) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItemBullet(com.vaadin.flow.component.charts.model.DataSeriesItemBullet) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 53 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class DynamicChangingChart method getFunnelConfiguration.

private Configuration getFunnelConfiguration() {
    DataSeries dataSeries = new DataSeries("Unique users");
    dataSeries.add(new DataSeriesItem("Website visits", 15654));
    dataSeries.add(new DataSeriesItem("Downloads", 4064));
    dataSeries.add(new DataSeriesItem("Requested price list", 1987));
    dataSeries.add(new DataSeriesItem("Invoice sent", 976));
    dataSeries.add(new DataSeriesItem("Finalized", 846));
    Configuration configuration = new Configuration();
    configuration.setTitle("Sales funnel");
    configuration.getLegend().setEnabled(false);
    PlotOptionsFunnel options = new PlotOptionsFunnel();
    options.setReversed(false);
    options.setNeckWidth("30%");
    options.setNeckHeight("30%");
    options.setWidth("70%");
    DataLabelsFunnel dataLabels = new DataLabelsFunnel();
    dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
    options.setDataLabels(dataLabels);
    dataSeries.setPlotOptions(options);
    configuration.addSeries(dataSeries);
    return configuration;
}
Also used : DataLabelsFunnel(com.vaadin.flow.component.charts.model.DataLabelsFunnel) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsFunnel(com.vaadin.flow.component.charts.model.PlotOptionsFunnel) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 54 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class DynamicChangingChart method getLineConfiguration.

private Configuration getLineConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setTitle("Solar Employment Growth by Sector, 2010-2016");
    configuration.setSubTitle("Source: thesolarfoundation.com");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle("Number of Employees");
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setVerticalAlign(VerticalAlign.MIDDLE);
    legend.setAlign(HorizontalAlign.RIGHT);
    PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
    plotOptionsSeries.setPointStart(2010);
    configuration.setPlotOptions(plotOptionsSeries);
    configuration.addSeries(new ListSeries("Installation", 43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175));
    configuration.addSeries(new ListSeries("Manufacturing", 24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434));
    configuration.addSeries(new ListSeries("Sales & Distribution", 11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387));
    configuration.addSeries(new ListSeries("Project Development", null, null, 7988, 12169, 15112, 22452, 34400, 34227));
    configuration.addSeries(new ListSeries("Other", 12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111));
    return configuration;
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 55 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.

the class FunnelChart method initDemo.

@Override
public void initDemo() {
    DataSeries dataSeries = new DataSeries("Unique users");
    dataSeries.add(new DataSeriesItem("Website visits", 15654));
    dataSeries.add(new DataSeriesItem("Downloads", 4064));
    dataSeries.add(new DataSeriesItem("Requested price list", 1987));
    dataSeries.add(new DataSeriesItem("Invoice sent", 976));
    dataSeries.add(new DataSeriesItem("Finalized", 846));
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Sales funnel");
    conf.getLegend().setEnabled(false);
    PlotOptionsFunnel options = new PlotOptionsFunnel();
    options.setReversed(false);
    options.setNeckWidth("30%");
    options.setNeckHeight("30%");
    options.setWidth("70%");
    DataLabelsFunnel dataLabels = new DataLabelsFunnel();
    dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
    options.setDataLabels(dataLabels);
    dataSeries.setPlotOptions(options);
    conf.addSeries(dataSeries);
    add(chart);
}
Also used : DataLabelsFunnel(com.vaadin.flow.component.charts.model.DataLabelsFunnel) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsFunnel(com.vaadin.flow.component.charts.model.PlotOptionsFunnel) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) Chart(com.vaadin.flow.component.charts.Chart)

Aggregations

Configuration (com.vaadin.flow.component.charts.model.Configuration)72 Chart (com.vaadin.flow.component.charts.Chart)48 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)32 YAxis (com.vaadin.flow.component.charts.model.YAxis)32 XAxis (com.vaadin.flow.component.charts.model.XAxis)25 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)24 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)20 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)19 Test (org.junit.Test)16 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)12 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)10 Path (java.nio.file.Path)10 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)9 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 Labels (com.vaadin.flow.component.charts.model.Labels)7 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)6 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)5 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)5 Pane (com.vaadin.flow.component.charts.model.Pane)4