Search in sources :

Example 1 with States

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

the class TimeSeriesWithTimeline method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Color[] colors = getThemeColors();
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("USD to EUR exchange rate from 2006 through 2008");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setMinRange(TWO_WEEKS);
    configuration.getxAxis().setTitle(new AxisTitle(""));
    configuration.getLegend().setEnabled(false);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Exchange rate"));
    yAxis.setMin(0.6);
    yAxis.setStartOnTick(false);
    yAxis.setShowFirstLabel(false);
    configuration.getTooltip().setShared(true);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
    fillColor.addColorStop(0, (SolidColor) colors[0]);
    fillColor.addColorStop(1, (SolidColor) colors[8]);
    plotOptions.setFillColor(fillColor);
    plotOptions.setLineWidth(1);
    plotOptions.setShadow(false);
    Marker marker = plotOptions.getMarker();
    marker.setEnabled(false);
    Hover hoverState = new Hover(true);
    hoverState.setRadius(5);
    States states = new States();
    states.setHover(hoverState);
    marker.setStates(states);
    Hover hoverStateForArea = new Hover(true);
    hoverStateForArea.setLineWidth(1);
    States statesForArea = new States();
    statesForArea.setHover(hoverStateForArea);
    plotOptions.setStates(statesForArea);
    plotOptions.setShadow(false);
    configuration.setPlotOptions(plotOptions);
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    ListSeries ls = new ListSeries();
    PlotOptionsArea options = new PlotOptionsArea();
    options.setPointInterval(DAY_IN_MILLIS);
    ls.setPlotOptions(options);
    ls.setName("USD to EUR");
    try {
        options.setPointStart(df.parse("2006/01/02").getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    ls.setData(USD_TO_EUR_EXCHANGE_RATES);
    configuration.setSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) 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) ParseException(java.text.ParseException) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with States

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

the class SplineWithPlotBands method getChart.

@SuppressWarnings("deprecation")
@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    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);
    Style style = new Style();
    style.setColor(LIGHT_GRAY);
    final PlotBand lightAir = new PlotBand();
    lightAir.setFrom(0.3);
    lightAir.setTo(1.5);
    lightAir.setColor(LIGHT_BLUE);
    lightAir.setLabel(new Label("Light air"));
    lightAir.getLabel().setStyle(style);
    final PlotBand lightBreeze = new PlotBand();
    lightBreeze.setFrom(1.5);
    lightBreeze.setTo(3.3);
    lightBreeze.setColor(TRANSPARENT);
    lightBreeze.setLabel(new Label("Light breeze"));
    lightBreeze.getLabel().setStyle(style);
    final PlotBand gentleBreeze = new PlotBand();
    gentleBreeze.setFrom(3.3);
    gentleBreeze.setTo(5.5);
    gentleBreeze.setColor(LIGHT_BLUE);
    gentleBreeze.setLabel(new Label("Gentle breeze"));
    gentleBreeze.getLabel().setStyle(style);
    final PlotBand moderateBreeze = new PlotBand();
    moderateBreeze.setFrom(5.5);
    moderateBreeze.setTo(8);
    moderateBreeze.setColor(TRANSPARENT);
    moderateBreeze.setLabel(new Label("Moderate breeze"));
    moderateBreeze.getLabel().setStyle(style);
    final PlotBand freshBreeze = new PlotBand();
    freshBreeze.setFrom(8);
    freshBreeze.setTo(11);
    freshBreeze.setColor(LIGHT_BLUE);
    freshBreeze.setLabel(new Label("Fresh breeze"));
    freshBreeze.getLabel().setStyle(style);
    final PlotBand strongBreeze = new PlotBand();
    strongBreeze.setFrom(11);
    strongBreeze.setTo(14);
    strongBreeze.setColor(TRANSPARENT);
    strongBreeze.setLabel(new Label("Strong breeze"));
    strongBreeze.getLabel().setStyle(style);
    final PlotBand highWind = new PlotBand();
    highWind.setFrom(14);
    highWind.setTo(15);
    highWind.setColor(LIGHT_BLUE);
    highWind.setLabel(new Label("High wind"));
    highWind.getLabel().setStyle(style);
    yAxis.setPlotBands(lightAir, lightBreeze, gentleBreeze, moderateBreeze, freshBreeze, strongBreeze, highWind);
    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);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Label(com.vaadin.addon.charts.model.Label) 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) Hover(com.vaadin.addon.charts.model.Hover) Style(com.vaadin.addon.charts.model.style.Style) 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 3 with States

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

the class TimeSeriesZoomable method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Color[] colors = getThemeColors();
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setZoomType(ZoomType.X);
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("USD to EUR exchange rate from 2006 through 2008");
    String title = Page.getCurrent().getWebBrowser().isTouchDevice() ? "Drag your finger over the plot to zoom in" : "Click and drag in the plot area to zoom in";
    configuration.getSubTitle().setText(title);
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setMinRange(TWO_WEEKS);
    configuration.getxAxis().setTitle(new AxisTitle(""));
    configuration.getLegend().setEnabled(false);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Exchange rate"));
    yAxis.setMin(0.6);
    yAxis.setStartOnTick(false);
    yAxis.setShowFirstLabel(false);
    configuration.getTooltip().setShared(true);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
    fillColor.addColorStop(0, (SolidColor) colors[0]);
    fillColor.addColorStop(1, (SolidColor) colors[8]);
    plotOptions.setFillColor(fillColor);
    plotOptions.setLineWidth(1);
    plotOptions.setShadow(false);
    Marker marker = new Marker();
    marker.setEnabled(false);
    Hover hoverState = new Hover(true);
    hoverState.setRadius(5);
    States states = new States();
    states.setHover(hoverState);
    marker.setStates(states);
    Hover hoverStateForArea = new Hover(true);
    hoverStateForArea.setLineWidth(1);
    States statesForArea = new States();
    statesForArea.setHover(hoverStateForArea);
    plotOptions.setStates(statesForArea);
    plotOptions.setMarker(marker);
    plotOptions.setShadow(false);
    configuration.setPlotOptions(plotOptions);
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    ListSeries ls = new ListSeries();
    PlotOptionsArea options = new PlotOptionsArea();
    options.setPointInterval(DAY_IN_MILLIS);
    ls.setPlotOptions(options);
    ls.setName("USD to EUR");
    try {
        options.setPointStart(df.parse("2006/01/02").getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    ls.setData(USD_TO_EUR_EXCHANGE_RATES);
    configuration.setSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) 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) ParseException(java.text.ParseException) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 4 with States

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

the class SVGGeneratorExample method getChart.

@Override
protected Component getChart() {
    final Chart chart;
    chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setZoomType(ZoomType.X);
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("USD to EUR exchange rate from 2006 through 2008");
    String title = Page.getCurrent().getWebBrowser().isTouchDevice() ? "Drag your finger over the plot to zoom in" : "Click and drag in the plot area to zoom in";
    configuration.getSubTitle().setText(title);
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setMinRange(TWO_WEEKS);
    configuration.getxAxis().setTitle(new AxisTitle(""));
    configuration.getLegend().setEnabled(false);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Exchange rate"));
    yAxis.setMin(0.6);
    yAxis.setStartOnTick(false);
    yAxis.setShowFirstLabel(false);
    configuration.getTooltip().setShared(true);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
    fillColor.addColorStop(0, SolidColor.AQUA);
    fillColor.addColorStop(1, SolidColor.BLACK);
    plotOptions.setFillColor(fillColor);
    plotOptions.setLineWidth(1);
    plotOptions.setShadow(false);
    Marker marker = new Marker();
    marker.setEnabled(false);
    Hover hoverState = new Hover(true);
    hoverState.setRadius(5);
    States states = new States();
    states.setHover(hoverState);
    plotOptions.setStates(states);
    plotOptions.setMarker(marker);
    plotOptions.setShadow(false);
    configuration.setPlotOptions(plotOptions);
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    ListSeries ls = new ListSeries();
    PlotOptionsArea options = new PlotOptionsArea();
    options.setPointInterval(DAY_IN_MILLIS);
    ls.setPlotOptions(options);
    ls.setName("USD to EUR");
    try {
        options.setPointStart(df.parse("2006/01/02").getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    ls.setData(USD_TO_EUR_EXCHANGE_RATES);
    configuration.setSeries(ls);
    chart.drawChart(configuration);
    Button export = new Button("Export");
    StreamResource.StreamSource svgStreamSource = createSVGStreamSource(chart);
    FileDownloader fileDownloader = new FileDownloader(new StreamResource(svgStreamSource, "chart.svg"));
    fileDownloader.extend(export);
    Button timelineToggle = new Button("Timeline toggle");
    timelineToggle.addClickListener(new Button.ClickListener() {

        boolean timeline = false;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            timeline = !timeline;
            chart.setTimeline(timeline);
        }
    });
    HorizontalLayout controls = new HorizontalLayout(export, timelineToggle);
    controls.setSpacing(true);
    addComponent(controls);
    setSpacing(true);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) String(java.lang.String) Marker(com.vaadin.addon.charts.model.Marker) States(com.vaadin.addon.charts.model.States) StreamResource(com.vaadin.server.StreamResource) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) FileDownloader(com.vaadin.server.FileDownloader) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Override(java.lang.Override) Chart(com.vaadin.addon.charts.Chart) Override(java.lang.Override)

Example 5 with States

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

the class MasterDetailChart method getDetailChart.

private Chart getDetailChart() {
    Chart detailChart = new Chart();
    detailChart.setHeight("100%");
    detailChart.setWidth("100%");
    Configuration configuration = detailChart.getConfiguration();
    configuration.getCredits().setEnabled(false);
    configuration.setTitle("Historical USD to EUR Exchange Rate");
    configuration.setSubTitle("Select an area by dragging across the lower chart");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getyAxis().setTitle(new AxisTitle((String) null));
    configuration.getyAxis().setMinRange(0.1);
    configuration.getTooltip().setFormatter("function() {var point = this.points[0];return '<b>'+ point.series.name +'</b><br/>'+Highcharts.dateFormat('%A %B %e %Y', this.x) + ':<br/>'+'1 USD = '+ Highcharts.numberFormat(point.y, 2) +' EUR';}");
    configuration.getTooltip().setShared(true);
    PlotOptionsLine series = new PlotOptionsLine();
    series.setPointInterval(DAY_IN_MILLIS);
    configuration.setPlotOptions(series);
    States states = new States();
    Hover hover = new Hover();
    hover.setRadius(3);
    states.setHover(hover);
    Marker marker = series.getMarker();
    marker.setEnabled(false);
    marker.setStates(states);
    marker.setRadius(2);
    series.setAnimation(false);
    ListSeries seriesList = new ListSeries();
    PlotOptionsLine plotOptionsLine = new PlotOptionsLine();
    plotOptionsLine.setPointInterval(DAY_IN_MILLIS);
    plotOptionsLine.setPointStart(Util.toHighchartsTS(DEMO_DATASET_START.atStartOfDay().toInstant(ZoneOffset.UTC)));
    seriesList.setPlotOptions(plotOptionsLine);
    seriesList.setName("USD to EUR");
    seriesList.setData(FULL_DEMO_DATA_SET);
    configuration.getLegend().setEnabled(false);
    configuration.setExporting(false);
    configuration.addSeries(seriesList);
    detailChart.drawChart(configuration);
    return detailChart;
}
Also used : States(com.vaadin.addon.charts.model.States) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) Marker(com.vaadin.addon.charts.model.Marker) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart)

Aggregations

Chart (com.vaadin.addon.charts.Chart)9 Configuration (com.vaadin.addon.charts.model.Configuration)9 ListSeries (com.vaadin.addon.charts.model.ListSeries)9 Marker (com.vaadin.addon.charts.model.Marker)9 States (com.vaadin.addon.charts.model.States)9 Hover (com.vaadin.addon.charts.model.Hover)8 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)7 YAxis (com.vaadin.addon.charts.model.YAxis)7 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)5 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)4 PlotBand (com.vaadin.addon.charts.model.PlotBand)3 Color (com.vaadin.addon.charts.model.style.Color)3 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)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 Button (com.vaadin.ui.Button)2