public Widget createExample() {
final Label selectedPointLabel = new Label(INSTRUCTION);
PlotWithOverviewModel model = new PlotWithOverviewModel(PlotModelStrategy.defaultStrategy());
PlotOptions plotOptions = new PlotOptions();
plotOptions.setDefaultLineSeriesOptions(new LineSeriesOptions().setLineWidth(1).setShow(true));
plotOptions.setDefaultPointsOptions(new PointsSeriesOptions().setRadius(2).setShow(true));
plotOptions.setDefaultShadowSize(1);
plotOptions.setLegendOptions(new LegendOptions().setShow(false));
plotOptions.setSelectionOptions(new SelectionOptions().setDragging(true).setMode("x"));
final PlotWithOverview plot = new PlotWithOverview(model, plotOptions);
// add hover listener
plot.addHoverListener(new PlotHoverListener() {
public void onPlotHover(Plot plot, PlotPosition position, PlotItem item) {
if (item != null) {
selectedPointLabel
.setText("x: " + item.getDataPoint().getX() + ", y: " + item.getDataPoint().getY());
} else {
selectedPointLabel.setText(INSTRUCTION);
}
}
}, false);
plot.addSelectionListener(new SelectionListener() {
public void selected(double x1, double y1, double x2, double y2) {
plot.setLinearSelection(x1, x2);
}
});
SeriesHandler s = plot.getModel().addSeries("Series 1");
s.add(new DataPoint(1, 2));
s.add(new DataPoint(2, 5));
s.add(new DataPoint(3, 7));
s.add(new DataPoint(4, 5));
s.add(new DataPoint(5, 3));
s.add(new DataPoint(6, 2));
s.add(new DataPoint(7, 5));
s.add(new DataPoint(8, 7));
s.add(new DataPoint(9, 5));
s.add(new DataPoint(10, 3));
// Start of Marking Code
Marking m = new Marking();
m.setX(new Range(2, 4));
m.setColor("#3BEFc3");
Marking m2 = new Marking();
m2.setX(new Range(5, 7));
m2.setColor("#cccccc");
Marking m3 = new Marking();
Range a = new Range();
a.setFrom(8);
m3.setX(a);
m3.setColor("#000000");
Markings ms = new Markings();
ms.addMarking(m);
ms.addMarking(m2);
ms.addMarking(m3);
// End of Marking Code
// Add Markings Objects to Grid Options
plotOptions.setGridOptions(new GridOptions().setHoverable(true).setMarkings(ms));
plot.setHeight(250);
plot.setOverviewHeight(60);