use of com.vaadin.ui.Button in project charts by vaadin.
the class SVGGeneratorExample method getChart.
@Override
protected Component getChart() {
final Chart chart;
chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setZoomType(ZoomType.X);
configuration.getChart().setSpacingRight(20);
configuration.getTitle().setText("USD to EUR exchange rate from 2006 through 2008");
String title = Page.getCurrent().getWebBrowser().isTouchDevice() ? "Drag your finger over the plot to zoom in" : "Click and drag in the plot area to zoom in";
configuration.getSubTitle().setText(title);
configuration.getxAxis().setType(AxisType.DATETIME);
configuration.getxAxis().setMinRange(TWO_WEEKS);
configuration.getxAxis().setTitle(new AxisTitle(""));
configuration.getLegend().setEnabled(false);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Exchange rate"));
yAxis.setMin(0.6);
yAxis.setStartOnTick(false);
yAxis.setShowFirstLabel(false);
configuration.getTooltip().setShared(true);
PlotOptionsArea plotOptions = new PlotOptionsArea();
GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
fillColor.addColorStop(0, SolidColor.AQUA);
fillColor.addColorStop(1, SolidColor.BLACK);
plotOptions.setFillColor(fillColor);
plotOptions.setLineWidth(1);
plotOptions.setShadow(false);
Marker marker = new Marker();
marker.setEnabled(false);
Hover hoverState = new Hover(true);
hoverState.setRadius(5);
States states = new States();
states.setHover(hoverState);
plotOptions.setStates(states);
plotOptions.setMarker(marker);
plotOptions.setShadow(false);
configuration.setPlotOptions(plotOptions);
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
ListSeries ls = new ListSeries();
PlotOptionsArea options = new PlotOptionsArea();
options.setPointInterval(DAY_IN_MILLIS);
ls.setPlotOptions(options);
ls.setName("USD to EUR");
try {
options.setPointStart(df.parse("2006/01/02").getTime());
} catch (ParseException e) {
e.printStackTrace();
}
ls.setData(USD_TO_EUR_EXCHANGE_RATES);
configuration.setSeries(ls);
chart.drawChart(configuration);
Button export = new Button("Export");
StreamResource.StreamSource svgStreamSource = createSVGStreamSource(chart);
FileDownloader fileDownloader = new FileDownloader(new StreamResource(svgStreamSource, "chart.svg"));
fileDownloader.extend(export);
Button timelineToggle = new Button("Timeline toggle");
timelineToggle.addClickListener(new Button.ClickListener() {
boolean timeline = false;
@Override
public void buttonClick(Button.ClickEvent event) {
timeline = !timeline;
chart.setTimeline(timeline);
}
});
HorizontalLayout controls = new HorizontalLayout(export, timelineToggle);
controls.setSpacing(true);
addComponent(controls);
setSpacing(true);
return chart;
}
use of com.vaadin.ui.Button 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.Button in project charts by vaadin.
the class ChartExportDemo method addButtons.
private void addButtons(Layout layout) {
exportButton2 = createExportButton("Download as SVG", "chart.svg", createSVGStreamSource());
exportButton3 = createExportButton("Download PDF containing the chart", "chart.pdf", createPdfStreamSource());
layout.addComponent(exportButton2);
layout.addComponent(exportButton3);
Button jPanelButton = new Button("Show JPanel with chart (needs server running in localhost)");
jPanelButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
SwingDemo.display(conf);
}
});
layout.addComponent(jPanelButton);
layout.setWidth("100%");
}
use of com.vaadin.ui.Button 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.Button 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);
}
Aggregations