Search in sources :

Example 61 with DataSeriesItem

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

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

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

the class FunnelChartExample method getChart.

@Override
protected Component getChart() {
    DataSeries dataSeries = new DataSeries("Unique users");
    dataSeries.add(new DataSeriesItem("Website visits", 15654));
    dataSeries.add(new DataSeriesItem("Downloads", 4064));
    dataSeries.add(new DataSeriesItem("Requested price list", 1987));
    dataSeries.add(new DataSeriesItem("Invoice sent", 976));
    dataSeries.add(new DataSeriesItem("Finalized", 846));
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Sales funnel");
    conf.getLegend().setEnabled(false);
    PlotOptionsFunnel options = new PlotOptionsFunnel();
    options.setReversed(false);
    options.setNeckWidth("30%");
    options.setNeckHeight("30%");
    options.setWidth("70%");
    DataLabelsFunnel dataLabels = new DataLabelsFunnel();
    dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
    options.setDataLabels(dataLabels);
    dataSeries.setPlotOptions(options);
    conf.addSeries(dataSeries);
    return chart;
}
Also used : DataLabelsFunnel(com.vaadin.addon.charts.model.DataLabelsFunnel) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsFunnel(com.vaadin.addon.charts.model.PlotOptionsFunnel) DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Chart(com.vaadin.addon.charts.Chart)

Example 64 with DataSeriesItem

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

the class PartialUpdateConflicts method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("200px");
    final ListSeries listSeries = new ListSeries(data);
    chart.getConfiguration().addSeries(listSeries);
    Button button = new Button("Do stuff", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            listSeries.addData(100, true, true);
            ArrayUtils.reverse(data);
            chart.getConfiguration().setSeries(new ListSeries(data));
            chart.drawChart();
        }
    });
    button.setId("b1");
    final Chart chart2 = new Chart();
    chart2.setHeight("200px");
    final DataSeries ds = new DataSeries();
    int i = 0;
    for (Integer value : data) {
        ds.add(new DataSeriesItem(i++, value));
    }
    chart2.getConfiguration().addSeries(ds);
    Button button2 = new Button("Do stuff DataSeries", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            final DataSeriesItem dataSeriesItem = new DataSeriesItem(ds.size(), new Random().nextInt(10));
            ds.add(dataSeriesItem);
            ArrayUtils.reverse(data);
            chart2.getConfiguration().setSeries(new ListSeries(data));
            chart2.drawChart();
        }
    });
    button2.setId("b2");
    VerticalLayout verticalLayout = new VerticalLayout(chart, button, chart2, button2);
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    return verticalLayout;
}
Also used : Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 65 with DataSeriesItem

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

the class BasicLineWithNavigator 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.getChart().setMarginRight(130);
    configuration.getChart().setMarginBottom(25);
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setType(AxisType.DATETIME);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setMin(-5d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
    DataSeries ds = new DataSeries();
    ds.setName("Tokyo");
    List<Double> values = Arrays.asList(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
    Calendar calendar = getCalendar();
    for (Double value : values) {
        DataSeriesItem item = new DataSeriesItem(calendar.getTime(), value);
        ds.add(item);
        calendar.add(Calendar.MONTH, 1);
    }
    configuration.addSeries(ds);
    ds = new DataSeries();
    ds.setName("New York");
    values = Arrays.asList(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
    calendar = getCalendar();
    for (Double value : values) {
        DataSeriesItem item = new DataSeriesItem(calendar.getTime(), value);
        ds.add(item);
        calendar.add(Calendar.MONTH, 1);
    }
    configuration.addSeries(ds);
    Navigator navigator = configuration.getNavigator();
    navigator.setMargin(75);
    navigator.setEnabled(true);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Navigator(com.vaadin.addon.charts.model.Navigator) Calendar(java.util.Calendar) 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)

Aggregations

DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)88 DataSeries (com.vaadin.addon.charts.model.DataSeries)81 Chart (com.vaadin.addon.charts.Chart)57 Configuration (com.vaadin.addon.charts.model.Configuration)51 YAxis (com.vaadin.addon.charts.model.YAxis)27 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)19 DataLabels (com.vaadin.addon.charts.model.DataLabels)17 XAxis (com.vaadin.addon.charts.model.XAxis)17 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 Random (java.util.Random)12 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)11 Test (org.junit.Test)11 Tooltip (com.vaadin.addon.charts.model.Tooltip)10 Marker (com.vaadin.addon.charts.model.Marker)9 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)8 PlotLine (com.vaadin.addon.charts.model.PlotLine)7 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)7 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)6 ListSeries (com.vaadin.addon.charts.model.ListSeries)6 Style (com.vaadin.addon.charts.model.style.Style)6