use of com.vaadin.ui.Slider in project charts by vaadin.
the class BasicLineWithAutoRotation method getChart.
@Override
protected Component getChart() {
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
final Chart chart = new Chart(ChartType.LINE);
chart.setHeight("400px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
XAxis xAxis = configuration.getxAxis();
xAxis.getLabels().setAutoRotation(new Number[] { -10, -20, -30, -40, 50, -60, -70, -80, -90 });
ListSeries ls = new ListSeries();
ls.setName("Tokyo");
ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("New York");
ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
configuration.addSeries(ls);
layout.addComponent(chart);
final Slider slider = new Slider("Width (50 - 100)", 50, 100);
slider.setWidth("200px");
slider.setValue(100d);
layout.addComponent(slider);
layout.addComponent(new Button("Set min width", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
slider.setValue(50d);
}
}));
slider.addValueChangeListener(event -> {
double newValue = slider.getValue();
chart.setWidth((float) newValue, Unit.PERCENTAGE);
});
return layout;
}
use of com.vaadin.ui.Slider in project charts by vaadin.
the class ModifyOnePoint method setup.
@Override
protected void setup() {
super.setup();
FormLayout formLayout = new FormLayout();
formLayout.setCaption("Special point settings, only updated point state is sent to client.");
formLayout.setMargin(true);
final Slider sliderX = new Slider();
sliderX.setMin(3);
sliderX.setMax(8);
sliderX.setResolution(1);
sliderX.setValue(4d);
sliderX.setCaption("X");
sliderX.addValueChangeListener(event -> {
dataSeriesItem.setX(sliderX.getValue());
series.update(dataSeriesItem);
});
sliderX.setWidth("200px");
formLayout.addComponent(sliderX);
final Slider sliderY = new Slider();
sliderY.setMin(0);
sliderY.setMax(10);
sliderY.setResolution(1);
sliderY.setValue(4d);
sliderY.setCaption("Y");
sliderY.addValueChangeListener(event -> {
dataSeriesItem.setY(sliderY.getValue());
updateItemInChart();
});
sliderY.setWidth("200px");
formLayout.addComponent(sliderY);
final ColorPicker colorPicker = new ColorPicker();
colorPicker.setValue(new com.vaadin.shared.ui.colorpicker.Color(255, 0, 0));
colorPicker.setCaption("Marker color");
colorPicker.addValueChangeListener(event -> {
dataSeriesItem.getMarker().setFillColor(new SolidColor(event.getValue().getCSS()));
updateItemInChart();
});
formLayout.addComponent(colorPicker);
Button c = new Button("Pseudorandom", new Button.ClickListener() {
Random r = new Random(0);
@Override
public void buttonClick(ClickEvent event) {
sliderX.setValue(r.nextDouble() * 5 + 3);
sliderY.setValue(r.nextDouble() * 10);
colorPicker.setValue(new com.vaadin.shared.ui.colorpicker.Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
}
});
c.setId("random");
formLayout.addComponent(c);
addComponentAsFirst(formLayout);
}
use of com.vaadin.ui.Slider in project charts by vaadin.
the class BasicColumnWithPointWidthAndRange method setup.
@Override
protected void setup() {
super.setup();
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setMargin(true);
horizontalLayout.setSpacing(true);
final Slider slider = new Slider("Value (1-100)", 1, 100);
slider.setWidth("200px");
slider.setValue(100d);
final NativeSelect<String> option = new NativeSelect<>();
option.setCaption("Option");
option.setItems("", "pointWidth", "pointRange");
option.setSelectedItem("pointWidth");
option.addSelectionListener(sc -> {
slider.setEnabled(!sc.getSelectedItem().get().equals(""));
});
horizontalLayout.addComponent(option);
horizontalLayout.addComponent(slider);
Button button = new Button("Apply");
button.addClickListener(e -> {
if (slider.isEnabled()) {
if (option.getSelectedItem().get().equals("pointWidth")) {
plotOptions.setPointWidth(slider.getValue());
plotOptions.setPointRange(null);
} else {
plotOptions.setPointRange(slider.getValue());
plotOptions.setPointWidth(null);
}
} else {
plotOptions.setPointRange(null);
plotOptions.setPointWidth(null);
}
chart.drawChart();
});
horizontalLayout.addComponent(button);
addComponent(horizontalLayout);
}
use of com.vaadin.ui.Slider in project charts by vaadin.
the class BasicLineWithTickCount method getChart.
@Override
protected Component getChart() {
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
final Chart chart = new Chart(ChartType.LINE);
chart.setHeight("400px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
XAxis xAxis = configuration.getxAxis();
Labels xLabels = new Labels();
xLabels.setAutoRotation(new Number[] { -10, -20, -30, -40, 50, -60, -70, -80, -90 });
xAxis.setLabels(xLabels);
final YAxis yAxis = configuration.getyAxis();
yAxis.setTickAmount(10);
ListSeries ls = new ListSeries();
ls.setName("Tokyo");
ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("New York");
ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
configuration.addSeries(ls);
layout.addComponent(chart);
final Slider slider = new Slider("Tick count (2 - 16)", 2, 16);
slider.setWidth("200px");
slider.setValue(10d);
layout.addComponent(slider);
layout.addComponent(new Button("Set max amount", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
slider.setValue(16d);
}
}));
slider.addValueChangeListener(event -> {
double newValue = slider.getValue();
yAxis.setTickAmount(newValue);
chart.drawChart();
});
return layout;
}
Aggregations