Search in sources :

Example 11 with Hover

use of com.vaadin.addon.charts.model.Hover in project charts by vaadin.

the class SplineWithPlotBandRemoveFunctionality method getChart.

@SuppressWarnings("deprecation")
@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Wind speed during two days");
    configuration.getSubTitle().setText("October 6th and 7th 2009 at two locations in Vik i Sogn, Norway");
    configuration.getxAxis().setType(AxisType.DATETIME);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Wind speed (m/s)"));
    yAxis.setMin(0);
    yAxis.setMinorGridLineWidth(0);
    yAxis.setGridLineWidth(0);
    // disable alternate grid color from Vaadin theme, disturbs
    // demonstrating plotbands
    yAxis.setAlternateGridColor(TRANSPARENT);
    createPlotBand(yAxis);
    configuration.getTooltip().setFormatter("Highcharts.dateFormat('%e. %b %Y, %H:00', this.x) +': '+ this.y +' m/s'");
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    configuration.setPlotOptions(plotOptions);
    plotOptions.setMarker(new Marker(false));
    plotOptions.getMarker().setLineWidth(4);
    plotOptions.getMarker().setSymbol(MarkerSymbolEnum.CIRCLE);
    States states = new States();
    Hover hover = new Hover(true);
    hover.setRadius(5);
    hover.setLineWidth(1);
    states.setHover(hover);
    plotOptions.getMarker().setStates(states);
    plotOptions.setPointInterval(ONE_HOUR);
    LocalDate date = LocalDate.of(2009, 9, 6);
    plotOptions.setPointStart(date.atStartOfDay().toInstant(ZoneOffset.UTC));
    ListSeries ls = new ListSeries();
    ls.setName("Hestavollane");
    ls.setData(4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1, 7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4, 8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5, 7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2, 3.0, 3.0);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Voll");
    ls.setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0, 0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3, 3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    final Button removePlotBand = new Button("Remove PlotBands");
    removePlotBand.setId("vaadin-button");
    removePlotBand.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            YAxis axis = chart.getConfiguration().getyAxis();
            if (axis.getPlotBands() == null || axis.getPlotBands().length == 0) {
                createPlotBand(chart.getConfiguration().getyAxis());
                removePlotBand.setCaption("Remove PlotBands");
            } else {
                chart.getConfiguration().getyAxis().setPlotBands(new PlotBand[] {});
                removePlotBand.setCaption("Restore PlotBands");
            }
            chart.drawChart(configuration);
        }
    });
    VerticalLayout verticalLayout = new VerticalLayout(removePlotBand, chart);
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    return verticalLayout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) ClickEvent(com.vaadin.ui.Button.ClickEvent) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) LocalDate(java.time.LocalDate) States(com.vaadin.addon.charts.model.States) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) Hover(com.vaadin.addon.charts.model.Hover) VerticalLayout(com.vaadin.ui.VerticalLayout) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Chart (com.vaadin.addon.charts.Chart)11 Configuration (com.vaadin.addon.charts.model.Configuration)11 Hover (com.vaadin.addon.charts.model.Hover)11 Marker (com.vaadin.addon.charts.model.Marker)11 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)10 YAxis (com.vaadin.addon.charts.model.YAxis)10 ListSeries (com.vaadin.addon.charts.model.ListSeries)8 States (com.vaadin.addon.charts.model.States)8 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)7 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)6 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)6 PlotBand (com.vaadin.addon.charts.model.PlotBand)3 Color (com.vaadin.addon.charts.model.style.Color)3 Labels (com.vaadin.addon.charts.model.Labels)2 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)2 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)2 XAxis (com.vaadin.addon.charts.model.XAxis)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 LocalDate (java.time.LocalDate)2