Search in sources :

Example 1 with AbstractSeries

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

the class AbstractSeriesBeanSerializer method serialize.

@Override
public void serialize(AbstractSeries bean, BeanSerializerDelegator<AbstractSeries> serializer, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    AbstractSeries series = bean;
    jgen.writeStartObject();
    // write other fields as per normal serialization rules
    serializer.serializeFields(bean, jgen, provider);
    if (series.getPlotOptions() != null && !(bean.getPlotOptions() instanceof PlotOptionsSeries)) {
        jgen.writeObjectField("type", series.getPlotOptions().getChartType());
    }
    jgen.writeEndObject();
}
Also used : AbstractSeries(com.vaadin.flow.component.charts.model.AbstractSeries) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries)

Example 2 with AbstractSeries

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

AbstractSeries (com.vaadin.flow.component.charts.model.AbstractSeries)2 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)2 Button (com.vaadin.flow.component.button.Button)1 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)1 Dimension (com.vaadin.flow.component.charts.model.Dimension)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