use of com.vaadin.server.StreamResource 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.server.StreamResource in project charts by vaadin.
the class ChartExportDemo method createExportButton.
private Button createExportButton(String caption, String filename, StreamSource ss) {
Button b = new Button(caption);
FileDownloader downloader = new FileDownloader(new StreamResource(ss, filename));
downloader.extend(b);
return b;
}
Aggregations