Search in sources :

Example 91 with VerticalLayout

use of com.vaadin.ui.VerticalLayout in project charts by vaadin.

the class PieWithGradientFill method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares at a specific website, 2010");
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setCursor(Cursor.POINTER);
    DataLabels dataLabels = new DataLabels();
    dataLabels.setEnabled(true);
    dataLabels.setColor(SolidColor.BLACK);
    dataLabels.setConnectorColor(SolidColor.BLACK);
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    conf.setPlotOptions(plotOptions);
    final DataSeries series = getBrowserMarketShareSeries();
    conf.setSeries(series);
    chart.drawChart();
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(false);
    layout.setMargin(false);
    layout.addComponent(chart);
    CheckBox button = new CheckBox("Slice one part");
    button.addValueChangeListener(e -> {
        series.setItemSliced(1, e.getValue());
    });
    layout.addComponent(button);
    return layout;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart)

Example 92 with VerticalLayout

use of com.vaadin.ui.VerticalLayout in project charts by vaadin.

the class AbstractPointClickCoordinatesChart method getChart.

@Override
protected Component getChart() {
    Label spaceLabel = new Label("Extra space to make sure coordinates are absolute, not relative.");
    spaceLabel.setHeight("100px");
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.addComponent(spaceLabel);
    verticalLayout.addComponent(createChart());
    verticalLayout.addComponent(lastAction);
    return verticalLayout;
}
Also used : Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 93 with VerticalLayout

use of com.vaadin.ui.VerticalLayout in project charts by vaadin.

the class ServerSideEvents method getChart.

@Override
protected Component getChart() {
    eventDetails.setId("eventDetails");
    lastEvent.setId("lastEvent");
    historyLayout.setId("history");
    chart = new Chart();
    chart.setId("chart");
    chart.setWidth("500px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SCATTER);
    configuration.getTitle().setText("Test server side events.");
    configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
    configuration.setExporting(true);
    configuration.getChart().setAnimation(false);
    configuration.getChart().setZoomType(ZoomType.XY);
    XAxis xAxis = configuration.getxAxis();
    xAxis.setMinPadding(0.2);
    xAxis.setMaxPadding(0.2);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    PlotLine plotline = new PlotLine();
    plotline.setValue(0);
    plotline.setWidth(1);
    plotline.setColor(new SolidColor("#808080"));
    yAxis.setPlotLines(new PlotLine[] { plotline });
    yAxis.setMinPadding(0.2);
    yAxis.setMaxPadding(0.2);
    YAxis yAxis1 = new YAxis();
    yAxis1.setTitle("Another axis");
    yAxis1.setOpposite(true);
    configuration.addyAxis(yAxis1);
    PlotOptionsSeries opt = new PlotOptionsSeries();
    opt.setLineWidth(1);
    opt.setShowCheckbox(true);
    opt.setAllowPointSelect(true);
    configuration.setPlotOptions(opt);
    configuration.setTooltip(new Tooltip(false));
    final DataSeries series1 = createDataSeries(0);
    final DataSeries series2 = createDataSeries(20);
    DataSeries series3 = createDataSeries(100);
    series3.get(0).setY(105);
    series3.get(3).setY(95);
    series3.setName("Another axis");
    series3.setyAxis(1);
    firstDataPoint = series1.get(0);
    firstDataPoint.setSelected(true);
    configuration.setSeries(series1, series2, series3);
    chart.drawChart(configuration);
    final Layout toggles = createControls();
    Layout eventListeners = addEventListeners();
    chart.setSeriesVisibilityTogglingDisabled(false);
    visibilityToggling.setValue(false);
    lastEvent.setCaption("Last event");
    eventDetails.setCaption("Details");
    historyLayout.setCaption("History");
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.addComponent(toggles);
    HorizontalLayout chartAndListeners = new HorizontalLayout(chart, eventListeners);
    chartAndListeners.setSizeUndefined();
    chartAndListeners.setSpacing(true);
    layout.addComponent(chartAndListeners);
    layout.addComponent(lastEvent);
    layout.addComponent(eventDetails);
    layout.addComponent(historyLayout);
    return layout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Tooltip(com.vaadin.addon.charts.model.Tooltip) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) XAxis(com.vaadin.addon.charts.model.XAxis) HorizontalLayout(com.vaadin.ui.HorizontalLayout) VerticalLayout(com.vaadin.ui.VerticalLayout) Layout(com.vaadin.ui.Layout) HorizontalLayout(com.vaadin.ui.HorizontalLayout) VerticalLayout(com.vaadin.ui.VerticalLayout) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 94 with VerticalLayout

use of com.vaadin.ui.VerticalLayout in project charts by vaadin.

the class SplineWithPlotBandRemoveFunctionality method getChart.

@SuppressWarnings("deprecation")
@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Wind speed during two days");
    configuration.getSubTitle().setText("October 6th and 7th 2009 at two locations in Vik i Sogn, Norway");
    configuration.getxAxis().setType(AxisType.DATETIME);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Wind speed (m/s)"));
    yAxis.setMin(0);
    yAxis.setMinorGridLineWidth(0);
    yAxis.setGridLineWidth(0);
    // disable alternate grid color from Vaadin theme, disturbs
    // demonstrating plotbands
    yAxis.setAlternateGridColor(TRANSPARENT);
    createPlotBand(yAxis);
    configuration.getTooltip().setFormatter("Highcharts.dateFormat('%e. %b %Y, %H:00', this.x) +': '+ this.y +' m/s'");
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    configuration.setPlotOptions(plotOptions);
    plotOptions.setMarker(new Marker(false));
    plotOptions.getMarker().setLineWidth(4);
    plotOptions.getMarker().setSymbol(MarkerSymbolEnum.CIRCLE);
    States states = new States();
    Hover hover = new Hover(true);
    hover.setRadius(5);
    hover.setLineWidth(1);
    states.setHover(hover);
    plotOptions.getMarker().setStates(states);
    plotOptions.setPointInterval(ONE_HOUR);
    LocalDate date = LocalDate.of(2009, 9, 6);
    plotOptions.setPointStart(date.atStartOfDay().toInstant(ZoneOffset.UTC));
    ListSeries ls = new ListSeries();
    ls.setName("Hestavollane");
    ls.setData(4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1, 7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4, 8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5, 7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2, 3.0, 3.0);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Voll");
    ls.setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0, 0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3, 3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    final Button removePlotBand = new Button("Remove PlotBands");
    removePlotBand.setId("vaadin-button");
    removePlotBand.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            YAxis axis = chart.getConfiguration().getyAxis();
            if (axis.getPlotBands() == null || axis.getPlotBands().length == 0) {
                createPlotBand(chart.getConfiguration().getyAxis());
                removePlotBand.setCaption("Remove PlotBands");
            } else {
                chart.getConfiguration().getyAxis().setPlotBands(new PlotBand[] {});
                removePlotBand.setCaption("Restore PlotBands");
            }
            chart.drawChart(configuration);
        }
    });
    VerticalLayout verticalLayout = new VerticalLayout(removePlotBand, chart);
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    return verticalLayout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) ClickEvent(com.vaadin.ui.Button.ClickEvent) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) LocalDate(java.time.LocalDate) States(com.vaadin.addon.charts.model.States) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) Hover(com.vaadin.addon.charts.model.Hover) VerticalLayout(com.vaadin.ui.VerticalLayout) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 95 with VerticalLayout

use of com.vaadin.ui.VerticalLayout in project charts by vaadin.

the class PartialUpdateConflicts method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("200px");
    final ListSeries listSeries = new ListSeries(data);
    chart.getConfiguration().addSeries(listSeries);
    Button button = new Button("Do stuff", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            listSeries.addData(100, true, true);
            ArrayUtils.reverse(data);
            chart.getConfiguration().setSeries(new ListSeries(data));
            chart.drawChart();
        }
    });
    button.setId("b1");
    final Chart chart2 = new Chart();
    chart2.setHeight("200px");
    final DataSeries ds = new DataSeries();
    int i = 0;
    for (Integer value : data) {
        ds.add(new DataSeriesItem(i++, value));
    }
    chart2.getConfiguration().addSeries(ds);
    Button button2 = new Button("Do stuff DataSeries", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            final DataSeriesItem dataSeriesItem = new DataSeriesItem(ds.size(), new Random().nextInt(10));
            ds.add(dataSeriesItem);
            ArrayUtils.reverse(data);
            chart2.getConfiguration().setSeries(new ListSeries(data));
            chart2.drawChart();
        }
    });
    button2.setId("b2");
    VerticalLayout verticalLayout = new VerticalLayout(chart, button, chart2, button2);
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    return verticalLayout;
}
Also used : Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Aggregations

VerticalLayout (com.vaadin.ui.VerticalLayout)101 Label (com.vaadin.ui.Label)38 HorizontalLayout (com.vaadin.ui.HorizontalLayout)25 Button (com.vaadin.ui.Button)24 Chart (com.vaadin.addon.charts.Chart)18 ClickEvent (com.vaadin.ui.Button.ClickEvent)15 Link (com.vaadin.ui.Link)15 ExternalResource (com.vaadin.server.ExternalResource)11 Configuration (com.vaadin.addon.charts.model.Configuration)10 ListSeries (com.vaadin.addon.charts.model.ListSeries)9 ClickListener (com.vaadin.ui.Button.ClickListener)8 PostConstruct (javax.annotation.PostConstruct)8 YAxis (com.vaadin.addon.charts.model.YAxis)7 DataSeries (com.vaadin.addon.charts.model.DataSeries)6 Panel (com.vaadin.ui.Panel)6 XAxis (com.vaadin.addon.charts.model.XAxis)5 Embedded (com.vaadin.ui.Embedded)5 TextField (com.vaadin.ui.TextField)5 PointClickEvent (com.vaadin.addon.charts.PointClickEvent)4 PointClickListener (com.vaadin.addon.charts.PointClickListener)4