Search in sources :

Example 1 with Dimension

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

the class ServerSideEvents method createControls.

private Component createControls() {
    visibilityToggling = new Checkbox("Disable series visibility toggling");
    visibilityToggling.setId("visibilityToggler");
    visibilityToggling.addValueChangeListener(e -> chart.setVisibilityTogglingDisabled(visibilityToggling.getValue()));
    visibilityToggling.setValue(false);
    final Button firstSeriesVisible = new Button("Hide first series", e -> {
        Series firstSeries = chart.getConfiguration().getSeries().get(0);
        ((AbstractSeries) firstSeries).setVisible(!hideSeries);
        hideSeries = !hideSeries;
    });
    firstSeriesVisible.setId("hideFirstSeries");
    final RadioButtonGroup<Dimension> zoomLevels = new RadioButtonGroup<>();
    zoomLevels.setItems(Dimension.XY, Dimension.X, Dimension.Y);
    zoomLevels.setValue(Dimension.XY);
    zoomLevels.addValueChangeListener(event -> {
        chart.getConfiguration().getChart().setZoomType(zoomLevels.getValue());
        chart.drawChart();
    });
    Button resetHistory = new Button("Reset history");
    resetHistory.setId("resetHistory");
    resetHistory.addClickListener(event -> {
        historyLayout.removeAll();
    });
    Button toggleExtremes = new Button("Toggle Extremes");
    toggleExtremes.setId("toggleExtremes");
    toggleExtremes.addClickListener(e -> {
        if (setExtremes) {
            chart.getConfiguration().getyAxes().getAxis(0).setExtremes(9, 15);
        } else {
            chart.getConfiguration().resetZoom();
        }
        setExtremes = !setExtremes;
    });
    HorizontalLayout controls = new HorizontalLayout();
    controls.setId("controls");
    controls.add(visibilityToggling);
    controls.add(firstSeriesVisible);
    controls.add(zoomLevels);
    controls.add(resetHistory);
    controls.add(toggleExtremes);
    return controls;
}
Also used : PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Series(com.vaadin.flow.component.charts.model.Series) AbstractSeries(com.vaadin.flow.component.charts.model.AbstractSeries) Button(com.vaadin.flow.component.button.Button) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) RadioButtonGroup(com.vaadin.flow.component.radiobutton.RadioButtonGroup) Dimension(com.vaadin.flow.component.charts.model.Dimension) AbstractSeries(com.vaadin.flow.component.charts.model.AbstractSeries) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Aggregations

Button (com.vaadin.flow.component.button.Button)1 AbstractSeries (com.vaadin.flow.component.charts.model.AbstractSeries)1 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)1 Dimension (com.vaadin.flow.component.charts.model.Dimension)1 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)1 Series (com.vaadin.flow.component.charts.model.Series)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 RadioButtonGroup (com.vaadin.flow.component.radiobutton.RadioButtonGroup)1