use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class TimeSeriesIntervalUnit method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setSpacingRight(20);
configuration.getTitle().setText("Point interval test");
configuration.getxAxis().setType(AxisType.DATETIME);
final PlotOptionsSeries plotOptions = new PlotOptionsSeries();
try {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
plotOptions.setPointStart(df.parse("20150101"));
} catch (ParseException e) {
e.printStackTrace();
}
plotOptions.setPointInterval(1);
plotOptions.setPointIntervalUnit(IntervalUnit.MONTH);
configuration.setPlotOptions(plotOptions);
ListSeries ls = new ListSeries();
ls.setData(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
configuration.setSeries(ls);
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
layout.addComponent(chart);
layout.addComponent(new Button("one day interval", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
plotOptions.setPointInterval(24 * 3600 * 1000);
plotOptions.setPointIntervalUnit(null);
chart.drawChart();
}
}));
return layout;
}
use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class TimeSeriesZoomable method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Color[] colors = getThemeColors();
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) colors[0]);
fillColor.addColorStop(1, (SolidColor) colors[8]);
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);
marker.setStates(states);
Hover hoverStateForArea = new Hover(true);
hoverStateForArea.setLineWidth(1);
States statesForArea = new States();
statesForArea.setHover(hoverStateForArea);
plotOptions.setStates(statesForArea);
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);
return chart;
}
use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class AreaSplineSite method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.AREASPLINE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Monthly supply and demand");
conf.setSubTitle("Last six months");
Legend legend = conf.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setFloating(true);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(150);
legend.setY(100);
Tooltip tooltip = conf.getTooltip();
tooltip.setValueSuffix("t");
tooltip.setShared(true);
XAxis xAxis = conf.getxAxis();
xAxis.setCategories("January", "February", "March", "April", "May", "June");
YAxis yAxis = conf.getyAxis();
yAxis.setTitle("Metric tons");
conf.addSeries(new ListSeries("Supply", 35, 28, 45, 60, 80, 74));
conf.addSeries(new ListSeries("Demand", 29, 11, 50, 63, 65, 61));
return chart;
}
use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class WebXYChartSelection method createScatterChart.
private Chart createScatterChart() {
final Chart scatterChart = new Chart(ChartType.SCATTER);
scatterChart.setId("chart");
scatterChart.getConfiguration().getChart().setZoomType(ZoomType.XY);
scatterChart.getConfiguration().disableCredits();
scatterChart.getConfiguration().setTitle("Selections as area ranges");
scatterChart.getConfiguration().setSubTitle("Drag with mouse to make selections. Click the legend items to toggle visibility.");
PlotOptionsScatter scatterOptions = new PlotOptionsScatter();
scatterOptions.setAnimation(false);
scatterOptions.setPointStart(1);
DataSeries series = new DataSeries();
series.setPlotOptions(scatterOptions);
series.setName("Original");
Random random = new Random(0);
for (int i = 0; i < 20; i++) {
DataSeriesItem dsi = new DataSeriesItem();
dsi.setY(random.nextInt(10));
dsi.setX(random.nextInt(10));
series.add(dsi);
}
scatterChart.getConfiguration().addSeries(series);
scatterChart.addChartSelectionListener(new ChartSelectionListener() {
@Override
public void onSelection(ChartSelectionEvent event) {
double xStart = event.getSelectionStart();
double xEnd = event.getSelectionEnd();
double yStart = event.getValueStart();
double yEnd = event.getValueEnd();
Number[][] data = new Number[][] { { xStart, yStart, yEnd }, { xEnd, yStart, yEnd } };
PlotOptionsArearange areaRangePlot = new PlotOptionsArearange();
areaRangePlot.setFillOpacity(0.1f);
areaRangePlot.setLineWidth(0);
RangeSeries selectionSeries = new RangeSeries("Selection", data);
selectionSeries.setPlotOptions(areaRangePlot);
scatterChart.getConfiguration().addSeries(selectionSeries);
scatterChart.drawChart();
areaRangePlot.setAnimation(false);
}
});
scatterChart.drawChart();
return scatterChart;
}
use of com.vaadin.addon.charts.Chart in project charts by vaadin.
the class LibraryData method getChart.
@Override
protected Component getChart() {
chart = new Chart(ChartType.BAR);
chart.setSizeFull();
Configuration config = chart.getConfiguration();
boolean inverted = config.getChart().getInverted();
config.getChart().setInverted(!inverted);
config.getLegend().setEnabled(false);
YAxis axis = new YAxis();
axis.setTitle("Pages");
config.addyAxis(axis);
series = new DataSeries();
config.setSeries(series);
updateChart();
return chart;
}
Aggregations