Search in sources :

Example 1 with DataSeriesItemBullet

use of com.vaadin.flow.component.charts.model.DataSeriesItemBullet 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)

Aggregations

Chart (com.vaadin.flow.component.charts.Chart)1 Configuration (com.vaadin.flow.component.charts.model.Configuration)1 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)1 DataSeriesItemBullet (com.vaadin.flow.component.charts.model.DataSeriesItemBullet)1 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)1 PlotOptionsBullet (com.vaadin.flow.component.charts.model.PlotOptionsBullet)1 YAxis (com.vaadin.flow.component.charts.model.YAxis)1 SolidColor (com.vaadin.flow.component.charts.model.style.SolidColor)1