use of com.vaadin.addon.charts.PointClickEvent 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.PointClickEvent 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.PointClickEvent in project charts by vaadin.
the class TreeMapPointClick method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.TREEMAP);
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
lastAction.setValue(event.getClass().getSimpleName());
}
});
chart.getConfiguration().addSeries(createSeries());
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.addComponent(chart);
verticalLayout.addComponent(lastAction);
return verticalLayout;
}
use of com.vaadin.addon.charts.PointClickEvent in project charts by vaadin.
the class DateAxisAndClickEvent method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Date axis and click events");
configuration.getChart().setType(ChartType.SPLINE);
configuration.getxAxis().setType(AxisType.DATETIME);
Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.HOUR_OF_DAY, 12);
c.set(2013, 2, 11);
DataSeries dataSeries = new DataSeries();
Number[] values = new Number[] { 71.5, 29.9, 106.4 };
Random r = new Random(0);
for (Number number : values) {
c.add(Calendar.MINUTE, r.nextInt(5));
DataSeriesItem item = new DataSeriesItem(c.getTime(), number);
dataSeries.add(item);
}
configuration.addSeries(dataSeries);
chart.drawChart(configuration);
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
/*
* The axis value is in client side library's raw format: unix
* timestamp, "shifted" to UTC time zone
*/
;
double timeStampShiftedToUc = event.getxAxisValue();
/*
* When working with Date objects, developers probably want to
* convert it to Date object at their local time zone.
*/
Notification.show("Clicked @ " + Util.toServerInstant(timeStampShiftedToUc));
}
});
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
/*
* Same with point clicks...
*/
;
double timeStampShiftedToUc = event.getX();
Notification.show("Clicked Point with Date value " + Util.toServerInstant(timeStampShiftedToUc));
}
});
return chart;
}
Aggregations