use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class OverrideStackingForSpecificSeries method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle(new Title("Stacked column chart"));
XAxis xAxis = new XAxis();
xAxis.setCategories(new String[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" });
conf.addxAxis(xAxis);
YAxis yAxis = new YAxis();
yAxis.setMin(0);
yAxis.setTitle(new AxisTitle("Total fruit consumption"));
StackLabels sLabels = new StackLabels(true);
Style slStyle = new Style();
slStyle.setFontWeight(FontWeight.BOLD);
slStyle.setColor(new SolidColor("gray"));
sLabels.setStyle(slStyle);
yAxis.setStackLabels(sLabels);
conf.addyAxis(yAxis);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("'<b>'+ this.x +'</b><br/>'+this.series.name +': '" + "+ this.y +'<br/>'+'Total: '+ this.point.stackTotal");
conf.setTooltip(tooltip);
PlotOptionsColumn plotOptions = new PlotOptionsColumn();
plotOptions.setStacking(Stacking.NORMAL);
DataLabels labels = new DataLabels();
labels.setEnabled(true);
labels.setColor(new SolidColor("white"));
plotOptions.setDataLabels(labels);
conf.setPlotOptions(plotOptions);
conf.addSeries(new ListSeries("John", new Number[] { 5, 3, 4, 7, 2 }));
conf.addSeries(new ListSeries("Jane", new Number[] { 2, 2, 3, 2, 1 }));
ListSeries series = new ListSeries("Joe", new Number[] { 3, 4, 4, 2, 5 });
PlotOptionsColumn joePlotOptions = new PlotOptionsColumn();
joePlotOptions.setStacking(Stacking.NONE);
series.setPlotOptions(joePlotOptions);
conf.addSeries(series);
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class ClickToAddPoint method getChart.
@Override
protected Component getChart() {
lastAction.setId("lastAction");
eventDetails.setId("eventDetails");
chart = new Chart();
chart.setId("chart");
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("User supplied data");
configuration.getSubTitle().setText("Click the plot area to add a point. Click a point to remove it.");
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
Legend legend = configuration.getLegend();
legend.setEnabled(false);
configuration.setExporting(false);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setLineWidth(1);
configuration.setPlotOptions(opt);
final DataSeries series = new DataSeries();
series.add(new DataSeriesItem(20, 20));
series.add(new DataSeriesItem(80, 80));
configuration.setSeries(series);
chart.drawChart(configuration);
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
double x = Math.round(event.getxAxisValue());
double y = Math.round(event.getyAxisValue());
series.add(new DataSeriesItem(x, y));
lastAction.setValue("Added point " + x + "," + y);
eventDetails.setValue(createEventString(event));
}
});
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
DataSeries ds = (DataSeries) event.getSeries();
DataSeriesItem dataSeriesItem2 = ds.get(event.getPointIndex());
ds.remove(dataSeriesItem2);
lastAction.setValue("Removed point at index " + event.getPointIndex());
eventDetails.setValue(createEventString(event));
}
});
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.setSpacing(false);
verticalLayout.setMargin(false);
verticalLayout.addComponent(chart);
verticalLayout.addComponent(lastAction);
verticalLayout.addComponent(eventDetails);
return verticalLayout;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class ServerSideEvents method getChart.
@Override
protected Component getChart() {
eventDetails.setId("eventDetails");
lastEvent.setId("lastEvent");
historyLayout.setId("history");
chart = new Chart();
chart.setId("chart");
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("Test server side events.");
configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
configuration.setExporting(true);
configuration.getChart().setAnimation(false);
configuration.getChart().setZoomType(ZoomType.XY);
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
PlotLine plotline = new PlotLine();
plotline.setValue(0);
plotline.setWidth(1);
plotline.setColor(new SolidColor("#808080"));
yAxis.setPlotLines(new PlotLine[] { plotline });
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
YAxis yAxis1 = new YAxis();
yAxis1.setTitle("Another axis");
yAxis1.setOpposite(true);
configuration.addyAxis(yAxis1);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setLineWidth(1);
opt.setShowCheckbox(true);
opt.setAllowPointSelect(true);
configuration.setPlotOptions(opt);
configuration.setTooltip(new Tooltip(false));
final DataSeries series1 = createDataSeries(0);
final DataSeries series2 = createDataSeries(20);
DataSeries series3 = createDataSeries(100);
series3.get(0).setY(105);
series3.get(3).setY(95);
series3.setName("Another axis");
series3.setyAxis(1);
firstDataPoint = series1.get(0);
firstDataPoint.setSelected(true);
configuration.setSeries(series1, series2, series3);
chart.drawChart(configuration);
final Layout toggles = createControls();
Layout eventListeners = addEventListeners();
chart.setSeriesVisibilityTogglingDisabled(false);
visibilityToggling.setValue(false);
lastEvent.setCaption("Last event");
eventDetails.setCaption("Details");
historyLayout.setCaption("History");
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.addComponent(toggles);
HorizontalLayout chartAndListeners = new HorizontalLayout(chart, eventListeners);
chartAndListeners.setSizeUndefined();
chartAndListeners.setSpacing(true);
layout.addComponent(chartAndListeners);
layout.addComponent(lastEvent);
layout.addComponent(eventDetails);
layout.addComponent(historyLayout);
return layout;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class DataProviderWithLotsOfData method createChart.
public static Chart createChart(Series ds) {
final Chart chart = new Chart(ChartType.AREA);
final Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("Data from Vaadin DataProvider");
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, new SolidColor("#4572A7"));
fillColor.addColorStop(1, new SolidColor(2, 0, 0, 0));
plotOptions.setFillColor(fillColor);
plotOptions.setLineWidth(1);
plotOptions.setShadow(false);
Marker marker = plotOptions.getMarker();
marker.setEnabled(false);
Hover hoverState = new Hover(true);
hoverState.setRadius(5);
hoverState.setLineWidth(1);
marker.getStates().setHover(hoverState);
plotOptions.getStates().setHover(new Hover(true));
plotOptions.setShadow(false);
configuration.setPlotOptions(plotOptions);
configuration.setSeries(ds);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.AxisTitle in project charts by vaadin.
the class DynamicExtremes method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.LINE);
configuration.getChart().setMarginRight(130);
configuration.getChart().setMarginBottom(25);
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setMin(-10d);
yAxis.setMax(30d);
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
yAxis.getTitle().setAlign(VerticalAlign.HIGH);
configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setDataLabels(new DataLabels(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-10d);
legend.setY(100d);
legend.setBorderWidth(0);
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);
ls = new ListSeries();
ls.setName("Berlin");
ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("London");
ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
configuration.addSeries(ls);
chart.drawChart(configuration);
final CheckBox extremes = new CheckBox("Switch extremes");
extremes.addValueChangeListener(e -> {
if (e.getValue()) {
chart.getConfiguration().getyAxes().getAxis(0).setExtremes(10, 15);
} else {
chart.getConfiguration().getyAxes().getAxis(0).setExtremes(-10, 30);
}
});
VerticalLayout layout = new VerticalLayout(chart, extremes);
return layout;
}
Aggregations