use of com.vaadin.addon.charts.ChartClickListener in project charts by vaadin.
the class AbstractPointClickCoordinatesChart method createChart.
protected Chart createChart() {
Chart chart = new Chart(type);
chart.setWidth("900px");
chart.setHeight("450px");
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
lastAction.setValue("PointClickEvent: absoluteX: " + event.getAbsoluteX() + " - absoluteY: " + event.getAbsoluteY());
}
});
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
lastAction.setValue("ChartClickEvent: absoluteX: " + event.getAbsoluteX() + " - absoluteY: " + event.getAbsoluteY());
}
});
addSeries(chart.getConfiguration());
return chart;
}
use of com.vaadin.addon.charts.ChartClickListener in project charts by vaadin.
the class Events method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
final Configuration configuration = chart.getConfiguration();
configuration.setTitle("Click to add point");
configuration.getChart().setType(ChartType.SPLINE);
final ListSeries series = new ListSeries(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(series);
chart.drawChart(configuration);
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
double getyAxisValue = event.getyAxisValue();
series.addData(getyAxisValue);
}
});
return chart;
}
use of com.vaadin.addon.charts.ChartClickListener in project charts by vaadin.
the class ServerSideEvents method addEventListeners.
private Layout addEventListeners() {
eventListeners = new VerticalLayout();
eventListeners.setCaption("Event listeners:");
final ChartClickListener listener = new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Chart click", "ChartClick", new ListenerToggle() {
@Override
public void add() {
chart.addChartClickListener(listener);
}
@Override
public void remove() {
chart.removeChartClickListener(listener);
}
});
final PointClickListener pcListener = new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Point click", "PointClick", new ListenerToggle() {
@Override
public void add() {
chart.addPointClickListener(pcListener);
}
@Override
public void remove() {
chart.removePointClickListener(pcListener);
}
});
final CheckboxClickListener cbListener = new CheckboxClickListener() {
@Override
public void onClick(CheckboxClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Checkbox click", "CheckboxClick", new ListenerToggle() {
@Override
public void add() {
chart.addCheckBoxClickListener(cbListener);
}
@Override
public void remove() {
chart.removeCheckBoxClickListener(cbListener);
}
});
final LegendItemClickListener legendItemListener = new LegendItemClickListener() {
@Override
public void onClick(LegendItemClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Legend item click", "LegendItemClick", new ListenerToggle() {
@Override
public void add() {
chart.addLegendItemClickListener(legendItemListener);
visibilityToggling.setValue(true);
}
@Override
public void remove() {
chart.removeLegendItemClickListener(legendItemListener);
}
});
final SeriesHideListener hideListener = new SeriesHideListener() {
@Override
public void onHide(SeriesHideEvent event) {
logEvent(event);
}
};
addToggleForListener("Series hide", "SeriesHide", new ListenerToggle() {
@Override
public void add() {
chart.addSeriesHideListener(hideListener);
}
@Override
public void remove() {
chart.removeSeriesHideListener(hideListener);
}
});
final SeriesShowListener show = new SeriesShowListener() {
@Override
public void onShow(SeriesShowEvent event) {
logEvent(event);
}
};
addToggleForListener("Series show", "SeriesShow", new ListenerToggle() {
@Override
public void add() {
chart.addSeriesShowListener(show);
}
@Override
public void remove() {
chart.removeSeriesShowListener(show);
}
});
final XAxesExtremesChangeListener xaxesListener = new XAxesExtremesChangeListener() {
@Override
public void onXAxesExtremesChange(XAxesExtremesChangeEvent event) {
logEvent(event);
}
};
addToggleForListener("XAxes extremes change", "XAxesExtremes", new ListenerToggle() {
@Override
public void add() {
chart.addXAxesExtremesChangeListener(xaxesListener);
}
@Override
public void remove() {
chart.removeXAxesExtremesChangeListener(xaxesListener);
}
});
final YAxesExtremesChangeListener yaxesListener = new YAxesExtremesChangeListener() {
@Override
public void onYAxesExtremesChange(YAxesExtremesChangeEvent event) {
logEvent(event);
}
};
addToggleForListener("Y axes extremes change", "YAxesExtremes", new ListenerToggle() {
@Override
public void add() {
chart.addYAxesExtremesChangeListener(yaxesListener);
}
@Override
public void remove() {
chart.removeYAxesExtremesChangeListener(yaxesListener);
}
});
final PointSelectListener selectListener = new PointSelectListener() {
@Override
public void onSelect(PointSelectEvent event) {
logEvent(event);
}
};
addToggleForListener("Point select", "PointSelect", new ListenerToggle() {
@Override
public void add() {
chart.addPointSelectListener(selectListener);
}
@Override
public void remove() {
chart.removePointSelectListener(selectListener);
}
});
final PointUnselectListener unselectListener = new PointUnselectListener() {
@Override
public void onUnselect(PointUnselectEvent event) {
logEvent(event);
}
};
addToggleForListener("Point unselect", "PointUnselect", new ListenerToggle() {
@Override
public void add() {
chart.addPointUnselectListener(unselectListener);
}
@Override
public void remove() {
chart.removePointUnselectListener(unselectListener);
}
});
return eventListeners;
}
use of com.vaadin.addon.charts.ChartClickListener in project charts by vaadin.
the class BasicLineGettingMousePointerPosition method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setId("chart");
Color[] colors = getThemeColors();
Configuration conf = chart.getConfiguration();
conf.getChart().setZoomType(ZoomType.XY);
conf.setTitle("Average Monthly Temperature and Rainfall in Tokyo");
conf.setSubTitle("Source: WorldClimate.com");
XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
conf.addxAxis(x);
YAxis primary = new YAxis();
primary.setTitle("Temperature");
Style style = new Style();
style.setColor(colors[0]);
primary.getTitle().setStyle(style);
conf.addyAxis(primary);
YAxis snd = new YAxis();
snd.setTitle("Rainfall");
snd.setOpposite(true);
style = new Style();
style.setColor(colors[1]);
snd.getTitle().setStyle(style);
conf.addyAxis(snd);
Tooltip tooltip = new Tooltip(false);
conf.setTooltip(tooltip);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setX(120);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setY(100);
legend.setFloating(true);
legend.setBackgroundColor(new SolidColor("#FFFFFF"));
conf.setLegend(legend);
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsColumn());
series.setName("Rainfall");
series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
series.setyAxis(1);
conf.addSeries(series);
series = new DataSeries();
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
series.setPlotOptions(plotOptions);
series.setName("Temperature");
series.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);
conf.addSeries(series);
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
Window win = new Window("PointClickEvent window");
win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
win.setPositionX(event.getAbsoluteX());
win.setPositionY(event.getAbsoluteY());
getUI().addWindow(win);
}
});
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
Window win = new Window("Chart Click Event Window");
win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
win.setPositionX(event.getAbsoluteX());
win.setPositionY(event.getAbsoluteY());
getUI().addWindow(win);
}
});
return chart;
}
use of com.vaadin.addon.charts.ChartClickListener 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;
}
Aggregations