Search in sources :

Example 6 with PlotBand

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

the class MasterDetailChart method getChart.

@Override
protected Component getChart() {
    VerticalLayout lo = new VerticalLayout();
    lo.setSpacing(false);
    lo.setMargin(false);
    lo.setWidth("100%");
    lo.setHeight("600px");
    final Chart masterChart = getMasterChart();
    final Chart detailChart = getDetailChart();
    masterChart.addChartSelectionListener(new ChartSelectionListener() {

        @Override
        public void onSelection(ChartSelectionEvent event) {
            long start = event.getSelectionStart().longValue();
            long end = event.getSelectionEnd().longValue();
            // set plot band to highlight the selection on the master chart
            PlotBand plotBand1 = new PlotBand();
            PlotBand plotBand2 = new PlotBand();
            plotBand1.setColor(new SolidColor(0, 0, 0, 0.2));
            plotBand2.setColor(new SolidColor(0, 0, 0, 0.2));
            plotBand1.setFrom(Util.toHighchartsTS(DEMO_DATASET_START.atStartOfDay().toInstant(ZoneOffset.UTC)));
            plotBand1.setTo(start);
            plotBand2.setFrom(end);
            plotBand2.setTo(Util.toHighchartsTS(DEMO_DATASET_END.atStartOfDay().toInstant(ZoneOffset.UTC)));
            masterChart.getConfiguration().getxAxis().setPlotBands(plotBand1, plotBand2);
            masterChart.drawChart();
            List<Number> list = MasterDetailChart.this.getPartialList(start, end);
            Configuration configuration = detailChart.getConfiguration();
            configuration.getChart().setAnimation(false);
            ListSeries detailData = (ListSeries) configuration.getSeries().get(0);
            PlotOptionsLine plotOptionsLine = (PlotOptionsLine) detailData.getPlotOptions();
            plotOptionsLine.setPointStart(start);
            detailData.setData(list);
            detailChart.drawChart(configuration);
        }
    });
    lo.addComponent(detailChart);
    lo.addComponent(masterChart);
    return lo;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) VerticalLayout(com.vaadin.ui.VerticalLayout) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) ArrayList(java.util.ArrayList) List(java.util.List) ChartSelectionEvent(com.vaadin.addon.charts.ChartSelectionEvent) ChartSelectionListener(com.vaadin.addon.charts.ChartSelectionListener) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart)

Example 7 with PlotBand

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

the class MasterDetailChart method getMasterChart.

private Chart getMasterChart() {
    Chart masterChart = new Chart(ChartType.AREA);
    masterChart.setHeight("80px");
    masterChart.setWidth("100%");
    masterChart.setId("master-chart");
    Configuration configuration = masterChart.getConfiguration();
    configuration.getChart().setZoomType(ZoomType.X);
    configuration.getChart().setReflow(false);
    configuration.getChart().setBorderWidth(0);
    configuration.getChart().setBackgroundColor(null);
    configuration.getChart().setMarginLeft(50);
    configuration.getChart().setMarginRight(20);
    configuration.getTitle().setText("");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setShowLastLabel(true);
    configuration.getxAxis().setMinRange(14 * DAY_IN_MILLIS);
    configuration.getxAxis().setTitle(new AxisTitle(""));
    PlotBand mask = new PlotBand();
    mask.setColor(new SolidColor(0, 0, 0, 0.2));
    mask.setFrom(Util.toHighchartsTS(DEMO_DATASET_START.atStartOfDay().toInstant(ZoneOffset.UTC)));
    mask.setTo(Util.toHighchartsTS(DEMO_DATASET_END.atStartOfDay().toInstant(ZoneOffset.UTC)));
    configuration.getxAxis().setPlotBands(mask);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setGridLineWidth(0);
    yAxis.setLabels(new Labels(false));
    yAxis.setTitle(new AxisTitle(""));
    yAxis.setMin(0.6);
    yAxis.setShowFirstLabel(false);
    configuration.getTooltip().setEnabled(false);
    configuration.getLegend().setEnabled(false);
    configuration.getCredits().setEnabled(false);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setLineWidth(1);
    plotOptions.setShadow(false);
    Hover hover = new Hover();
    hover.setLineWidth(1);
    States states = new States();
    states.setHover(hover);
    plotOptions.setStates(states);
    plotOptions.setEnableMouseTracking(false);
    plotOptions.setAnimation(false);
    configuration.setPlotOptions(plotOptions);
    ListSeries ls = new ListSeries();
    PlotOptionsArea masterPlotOptions = new PlotOptionsArea();
    GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
    fillColor.addColorStop(0, new SolidColor(69, 114, 167, 1));
    fillColor.addColorStop(1, new SolidColor(69, 114, 167, 0.5));
    masterPlotOptions.setFillColor(fillColor);
    masterPlotOptions.setPointInterval(24 * 3600 * 1000);
    masterPlotOptions.setMarker(new Marker(false));
    masterPlotOptions.setPointStart(Util.toHighchartsTS(DEMO_DATASET_START.atStartOfDay().toInstant(ZoneOffset.UTC)));
    ls.setPlotOptions(masterPlotOptions);
    ls.setName("USD to EUR");
    ls.setData(FULL_DEMO_DATA_SET);
    configuration.addSeries(ls);
    masterChart.drawChart(configuration);
    return masterChart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) Marker(com.vaadin.addon.charts.model.Marker) States(com.vaadin.addon.charts.model.States) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) 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)

Example 8 with PlotBand

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

the class AreaSpline method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREASPLINE);
    chart.setHeight("450px");
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Average fruit consumption during one week"));
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(150);
    legend.setY(100);
    conf.setLegend(legend);
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" });
    // add blue background for the weekend
    PlotBand plotBand = new PlotBand(4.5, 6.5, LIGHT_BLUE);
    plotBand.setZIndex(1);
    xAxis.setPlotBands(plotBand);
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle(new AxisTitle("Fruit units"));
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    // Customize tooltip formatting
    tooltip.setHeaderFormat("");
    tooltip.setPointFormat("{series.name}: {point.y} units");
    // Same could be achieved by defining following JS formatter funtion:
    // tooltip.setFormatter("function(){ return this.x +': '+ this.y +' units';}");
    // ... or its shorthand form:
    // tooltip.setFormatter("this.x +': '+ this.y +' units'");
    conf.setTooltip(tooltip);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setFillOpacity(0.5);
    conf.setPlotOptions(plotOptions);
    ListSeries o = new ListSeries("John", 3, 4, 3, 5, 4, 10);
    // Add last value separately
    o.addData(12);
    conf.addSeries(o);
    conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));
    chart.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) PlotBand(com.vaadin.addon.charts.model.PlotBand) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 9 with PlotBand

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

the class VUMeter method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("600px");
    chart.setHeight("200px");
    GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1);
    gradient.addColorStop(0, new SolidColor("#FFF4C6"));
    gradient.addColorStop(0.3, new SolidColor("#FFFFFF"));
    gradient.addColorStop(1, new SolidColor("#FFF4C6"));
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.getChart().setPlotBackgroundColor(gradient);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(1);
    configuration.setTitle("VU meter");
    Pane pane1 = new Pane(-45, 45);
    Pane pane2 = new Pane(-45, 45);
    pane1.setBackground(new Background[] {});
    pane2.setBackground(new Background[] {});
    pane1.setCenter("25%", "145%");
    pane2.setCenter("75%", "145%");
    pane1.setSize("300px");
    pane2.setSize("300");
    configuration.addPane(pane1);
    configuration.addPane(pane2);
    PlotBand plotBand1 = new PlotBand(0, 6, new SolidColor("#C02316"));
    plotBand1.setInnerRadius("100%");
    plotBand1.setOuterRadius("105%");
    PlotBand plotBand2 = new PlotBand(0, 6, new SolidColor("#C02316"));
    plotBand2.setInnerRadius("100%");
    plotBand2.setOuterRadius("105%");
    YAxis yAxis = new YAxis();
    yAxis.setPane(pane1);
    yAxis.setTitle("VU<br/><span style=\"font-size:8px\">Channel A</span>");
    yAxis.getTitle().setY(-40);
    yAxis.setMin(-20);
    yAxis.setMax(6);
    yAxis.setTickPosition(TickPosition.OUTSIDE);
    yAxis.setMinorTickPosition(TickPosition.OUTSIDE);
    Labels labels = new Labels();
    labels.setDistance(20);
    labels.setRotationPerpendicular();
    yAxis.setLabels(labels);
    yAxis.setPlotBands(plotBand1);
    YAxis yAxis2 = new YAxis();
    yAxis2.setPane(pane2);
    yAxis2.setTitle("VU<br/><span style=\"font-size:8px\">Channel B</span>");
    yAxis2.getTitle().setY(-40);
    yAxis2.setMin(-20);
    yAxis2.setMax(6);
    yAxis2.setTickPosition(TickPosition.OUTSIDE);
    yAxis2.setMinorTickPosition(TickPosition.OUTSIDE);
    labels = new Labels();
    labels.setDistance(20);
    labels.setRotationPerpendicular();
    yAxis2.setLabels(labels);
    yAxis2.setPlotBands(plotBand2);
    configuration.addyAxis(yAxis);
    configuration.addyAxis(yAxis2);
    PlotOptionsGauge gauge = new PlotOptionsGauge();
    gauge.setDataLabels(new DataLabels(false));
    gauge.setDial(new Dial());
    gauge.getDial().setRadius("100%");
    configuration.setPlotOptions(gauge);
    final ListSeries series1 = new ListSeries(-20);
    final ListSeries series2 = new ListSeries(-20);
    series1.setyAxis(0);
    series2.setyAxis(1);
    configuration.setSeries(series1, series2);
    runWhileAttached(chart, new Runnable() {

        final Random r = new Random(0);

        @Override
        public void run() {
            double left = series1.getData()[0].doubleValue();
            double inc = (r.nextDouble() - 0.5) * 3;
            double leftVal = left + inc;
            double rightVal = leftVal + inc / 3;
            if (leftVal < -20 || leftVal > 6) {
                leftVal = left - inc;
            }
            if (rightVal < -20 || rightVal > 6) {
                rightVal = leftVal;
            }
            series1.updatePoint(0, leftVal);
            series2.updatePoint(0, rightVal);
        }
    }, 500, 12000);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Pane(com.vaadin.addon.charts.model.Pane) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Dial(com.vaadin.addon.charts.model.Dial) Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 10 with PlotBand

use of com.vaadin.addon.charts.model.PlotBand 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

PlotBand (com.vaadin.addon.charts.model.PlotBand)10 Chart (com.vaadin.addon.charts.Chart)9 Configuration (com.vaadin.addon.charts.model.Configuration)9 ListSeries (com.vaadin.addon.charts.model.ListSeries)7 YAxis (com.vaadin.addon.charts.model.YAxis)7 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)5 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)4 Hover (com.vaadin.addon.charts.model.Hover)3 Labels (com.vaadin.addon.charts.model.Labels)3 Marker (com.vaadin.addon.charts.model.Marker)3 States (com.vaadin.addon.charts.model.States)3 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)3 Label (com.vaadin.addon.charts.model.Label)2 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)2 PlotOptionsGauge (com.vaadin.addon.charts.model.PlotOptionsGauge)2 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)2 XAxis (com.vaadin.addon.charts.model.XAxis)2 Style (com.vaadin.addon.charts.model.style.Style)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 LocalDate (java.time.LocalDate)2