Search in sources :

Example 16 with PlotOptionsSpline

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

the class SplineInverted method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setWidth("500px");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getChart().setInverted(true);
    configuration.getTitle().setText("Atmosphere Temperature by Altitude");
    configuration.getSubTitle().setText("According to the Standard Atmosphere Model");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setReversed(false);
    xAxis.setTitle(new AxisTitle("Altitude"));
    Labels labels = new Labels();
    labels.setFormatter("this.value + 'km'");
    labels.setEnabled(true);
    xAxis.setLabels(labels);
    xAxis.setMaxPadding(0.05);
    xAxis.setShowLastLabel(true);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setLineWidth(2);
    yAxis.setTitle(new AxisTitle("Temperature"));
    yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
    Labels labelsy = new Labels();
    labelsy.setEnabled(true);
    labelsy.setFormatter("this.value + '°'");
    yAxis.setLabels(labelsy);
    configuration.getTooltip().setFormatter("this.x +' km: '+this.y +'°C'");
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    plotOptions.setMarker(new Marker(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setEnabled(false);
    DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Temperature");
    series.addData(new Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }, { 30, -46.5 }, { 40, -22.1 }, { 50, -2.5 }, { 60, -27.7 }, { 70, -55.7 }, { 80, -76.5 } });
    configuration.setSeries(series);
    chart.drawChart(configuration);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) Labels(com.vaadin.addon.charts.model.Labels) DataSeries(com.vaadin.addon.charts.model.DataSeries) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) 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 17 with PlotOptionsSpline

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

the class SplineUpdatingEachSecond method getChart.

@Override
protected Component getChart() {
    final Random random = new Random();
    final Chart chart = new Chart();
    chart.setWidth("500px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Live random data");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setType(AxisType.DATETIME);
    xAxis.setTickPixelInterval(150);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
    configuration.getTooltip().setEnabled(false);
    configuration.getLegend().setEnabled(false);
    final DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
    }
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            final long x = System.currentTimeMillis();
            final double y = random.nextDouble();
            series.add(new DataSeriesItem(x, y), true, true);
        }
    }, 1000, 1000);
    configuration.setSeries(series);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) Random(java.util.Random) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 18 with PlotOptionsSpline

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

the class SplineUpdatingEachSecondWithCustomizedNewPoints method getChart.

@Override
protected Component getChart() {
    final Random random = new Random();
    final Chart chart = new Chart();
    chart.setWidth("500px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Live random data");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setType(AxisType.DATETIME);
    xAxis.setTickPixelInterval(150);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
    configuration.getTooltip().setEnabled(false);
    configuration.getLegend().setEnabled(false);
    final DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        DataSeriesItem item = new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble());
        series.add(item);
    }
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            final long x = System.currentTimeMillis();
            final double y = random.nextDouble();
            DataSeriesItem item = new DataSeriesItem(x, y);
            item.setName("Diipaiapa");
            Marker marker = new Marker();
            marker.setEnabled(true);
            boolean b = (new Random().nextInt(5) % 4 == 0);
            marker.setFillColor(new SolidColor(b ? "#ff0000" : "#000000"));
            item.setMarker(marker);
            series.add(item, true, true);
        }
    }, 1000, 1000);
    configuration.setSeries(series);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) Random(java.util.Random) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 19 with PlotOptionsSpline

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

Example 20 with PlotOptionsSpline

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

the class ChartConfiguration method plotOptionsSnippet3.

public void plotOptionsSnippet3(Configuration configuration) {
    PlotOptionsSpline lineOptions = new PlotOptionsSpline();
    PlotOptionsLine splineOptions = new PlotOptionsLine();
    setCommonProperties(lineOptions);
    setCommonProperties(splineOptions);
    configuration.setPlotOptions(lineOptions, splineOptions);
}
Also used : PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline)

Aggregations

PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)20 Configuration (com.vaadin.addon.charts.model.Configuration)18 Chart (com.vaadin.addon.charts.Chart)16 DataSeries (com.vaadin.addon.charts.model.DataSeries)14 YAxis (com.vaadin.addon.charts.model.YAxis)14 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)8 XAxis (com.vaadin.addon.charts.model.XAxis)8 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)8 Marker (com.vaadin.addon.charts.model.Marker)7 Style (com.vaadin.addon.charts.model.style.Style)6 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)5 Labels (com.vaadin.addon.charts.model.Labels)4 Legend (com.vaadin.addon.charts.model.Legend)4 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)4 PlotLine (com.vaadin.addon.charts.model.PlotLine)3 Tooltip (com.vaadin.addon.charts.model.Tooltip)3 Color (com.vaadin.addon.charts.model.style.Color)3 Random (java.util.Random)3 DateTimeLabelFormats (com.vaadin.addon.charts.model.DateTimeLabelFormats)2