Search in sources :

Example 61 with Configuration

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

the class LinesWithComplexHtmlTooltip method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Tooltip tooltip = new Tooltip();
    tooltip.setShared(true);
    tooltip.setUseHTML(true);
    tooltip.setHeaderFormat("<small>{point.key}</small><table>");
    tooltip.setPointFormat("<tr><td style=\"color: {series.color}\">{series.name}: </td><td style=\"text-align: right\"><b>{point.y} EUR</b></td></tr>");
    tooltip.setFooterFormat("</table>");
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Complex tooltip");
    configuration.setTooltip(tooltip);
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    ListSeries ls = new ListSeries();
    ls.setName("Short");
    ls.setData(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Long named series");
    Number[] data = new Number[] { 129.9, 171.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 195.6, 154.4 };
    for (int i = 0; i < data.length / 2; i++) {
        Number number = data[i];
        data[i] = data[data.length - i - 1];
        data[data.length - i - 1] = number;
    }
    ls.setData(data);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) Chart(com.vaadin.addon.charts.Chart)

Example 62 with Configuration

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

the class SplineUpdatingEachSecondWithTwoLines 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()));
    }
    final DataSeries series2 = new DataSeries();
    series2.setPlotOptions(new PlotOptionsSpline());
    series2.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        series2.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
    }
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            long x = System.currentTimeMillis();
            series.add(new DataSeriesItem(x, random.nextDouble()), true, true);
            series2.add(new DataSeriesItem(x, random.nextDouble()), true, true);
        }
    }, 1000, 1000);
    configuration.setSeries(series, series2);
    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 63 with Configuration

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

the class SplineWithItemLabels method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.SPLINE);
    Configuration configuration = chart.getConfiguration();
    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)"));
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    configuration.setPlotOptions(plotOptions);
    plotOptions.setMarker(new Marker(false));
    plotOptions.setPointInterval(ONE_HOUR);
    plotOptions.setPointStart(toDate("2009,09,06"));
    DataSeries ds = new DataSeries();
    ds.setName("Hestavollane");
    ds.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);
    DataSeriesItem item = new DataSeriesItem();
    item.setY(4.51);
    item.setDataLabels(getDataLabels());
    ds.add(item);
    configuration.addSeries(ds);
    ds = new DataSeries();
    ds.setName("Voll");
    ds.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);
    item = new DataSeriesItem();
    item.setY(0.27);
    item.setDataLabels(getDataLabels());
    ds.add(item);
    configuration.addSeries(ds);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) 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) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 64 with Configuration

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

the class BasicLineWithAutoRotation method getChart.

@Override
protected Component getChart() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(false);
    layout.setMargin(false);
    final Chart chart = new Chart(ChartType.LINE);
    chart.setHeight("400px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    XAxis xAxis = configuration.getxAxis();
    xAxis.getLabels().setAutoRotation(new Number[] { -10, -20, -30, -40, 50, -60, -70, -80, -90 });
    ListSeries ls = new ListSeries();
    ls.setName("Tokyo");
    ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("New York");
    ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
    configuration.addSeries(ls);
    layout.addComponent(chart);
    final Slider slider = new Slider("Width (50 - 100)", 50, 100);
    slider.setWidth("200px");
    slider.setValue(100d);
    layout.addComponent(slider);
    layout.addComponent(new Button("Set min width", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            slider.setValue(50d);
        }
    }));
    slider.addValueChangeListener(event -> {
        double newValue = slider.getValue();
        chart.setWidth((float) newValue, Unit.PERCENTAGE);
    });
    return layout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Slider(com.vaadin.ui.Slider) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis)

Example 65 with Configuration

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

the class BasicLineWithDataLabels method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.LINE);
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    plotOptions.setEnableMouseTracking(false);
    configuration.setPlotOptions(plotOptions);
    ListSeries ls = new ListSeries();
    ls.setName("Tokyo");
    ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("London");
    ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Configuration (com.vaadin.addon.charts.model.Configuration)257 Chart (com.vaadin.addon.charts.Chart)196 YAxis (com.vaadin.addon.charts.model.YAxis)100 DataSeries (com.vaadin.addon.charts.model.DataSeries)72 ListSeries (com.vaadin.addon.charts.model.ListSeries)70 XAxis (com.vaadin.addon.charts.model.XAxis)65 Test (org.junit.Test)58 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)56 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)54 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)51 Tooltip (com.vaadin.addon.charts.model.Tooltip)42 DataLabels (com.vaadin.addon.charts.model.DataLabels)41 Legend (com.vaadin.addon.charts.model.Legend)30 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)30 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)27 Elements (org.jsoup.select.Elements)27 Marker (com.vaadin.addon.charts.model.Marker)22 DesignContext (com.vaadin.ui.declarative.DesignContext)22 Element (org.jsoup.nodes.Element)22 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)20