Search in sources :

Example 1 with ZoomType

use of com.vaadin.addon.charts.model.ZoomType in project charts by vaadin.

the class ServerSideEvents method createControls.

private Layout createControls() {
    visibilityToggling = new CheckBox("Disable series visibility toggling");
    visibilityToggling.addValueChangeListener(e -> {
        chart.setSeriesVisibilityTogglingDisabled(visibilityToggling.getValue());
    });
    final Button firstSeriesVisible = new Button("Hide first series");
    firstSeriesVisible.setId("hideFirstSeries");
    firstSeriesVisible.addClickListener(new Button.ClickListener() {

        boolean hideSeries = true;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Series firstSeries = chart.getConfiguration().getSeries().get(0);
            ((AbstractSeries) firstSeries).setVisible(!hideSeries);
            hideSeries = !hideSeries;
            String caption = hideSeries ? "Hide first series" : "Show first series";
            firstSeriesVisible.setCaption(caption);
        }
    });
    Button setExtremes = new Button("Toggle extremes");
    setExtremes.setId("setExtremes");
    setExtremes.addClickListener(new Button.ClickListener() {

        public boolean extremesSet;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (extremesSet) {
                chart.getConfiguration().getxAxis().setExtremes(10, 90);
            } else {
                chart.getConfiguration().getxAxis().setExtremes(20, 80);
            }
            extremesSet = !extremesSet;
        }
    });
    final OptionGroup zoomLevels = new OptionGroup("Zoom Type");
    zoomLevels.addItem(ZoomType.XY);
    zoomLevels.addItem(ZoomType.X);
    zoomLevels.addItem(ZoomType.Y);
    zoomLevels.setValue(ZoomType.XY);
    zoomLevels.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            ZoomType zoom = (ZoomType) zoomLevels.getValue();
            chart.getConfiguration().getChart().setZoomType(zoom);
            chart.drawChart();
        }
    });
    Button resetHistory = new Button("Reset history");
    resetHistory.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            lastEvent.setValue(null);
            eventDetails.setValue(null);
            historyLayout.removeAllComponents();
        }
    });
    HorizontalLayout controls = new HorizontalLayout();
    controls.setId("controls");
    controls.setSpacing(true);
    controls.addComponent(visibilityToggling);
    controls.addComponent(firstSeriesVisible);
    controls.addComponent(setExtremes);
    controls.addComponent(zoomLevels);
    controls.addComponent(resetHistory);
    return controls;
}
Also used : ZoomType(com.vaadin.addon.charts.model.ZoomType) HorizontalLayout(com.vaadin.ui.HorizontalLayout) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) Series(com.vaadin.addon.charts.model.Series) AbstractSeries(com.vaadin.addon.charts.model.AbstractSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) OptionGroup(com.vaadin.v7.ui.OptionGroup) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) Property(com.vaadin.v7.data.Property)

Aggregations

AbstractSeries (com.vaadin.addon.charts.model.AbstractSeries)1 DataSeries (com.vaadin.addon.charts.model.DataSeries)1 PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)1 Series (com.vaadin.addon.charts.model.Series)1 ZoomType (com.vaadin.addon.charts.model.ZoomType)1 Button (com.vaadin.ui.Button)1 CheckBox (com.vaadin.ui.CheckBox)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Property (com.vaadin.v7.data.Property)1 OptionGroup (com.vaadin.v7.ui.OptionGroup)1