Search in sources :

Example 41 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class ColumnSite method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Earnings");
    conf.setSubTitle("2011 - 2014");
    XAxis xAxis = conf.getxAxis();
    xAxis.setCategories("2011", "2012", "2013", "2014");
    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("B€");
    Tooltip tooltip = conf.getTooltip();
    tooltip.setPointFormat("{series.name}: {point.y} B€");
    conf.addSeries(new ListSeries("Revenue", 1.5, 1.8, 1.2, 2.3));
    conf.addSeries(new ListSeries("Expenses", 1.2, 1.1, 1.3, 0.9));
    conf.addSeries(new ListSeries("Net income", -0.3, 0.7, -0.1, 1.4));
    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) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 42 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class PieSite method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Revenue by industry");
    conf.setSubTitle("2015");
    Tooltip tooltip = conf.getTooltip();
    tooltip.setPointFormat("<b>{point.percentage:.1f}%</b>");
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setAllowPointSelect(true);
    plotOptions.setCursor(Cursor.POINTER);
    plotOptions.setShowInLegend(true);
    DataLabels dataLabels = plotOptions.getDataLabels();
    dataLabels.setEnabled(true);
    dataLabels.setFormat("{point.name}: {point.y:.1f} M€");
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries("Revenue");
    series.add(new DataSeriesItem("Aerospace", 90.0));
    series.add(new DataSeriesItem("Medical", 53.6));
    series.add(new DataSeriesItem("Agriculture", 25.6));
    series.add(new DataSeriesItem("Automotive", 17.0));
    series.add(new DataSeriesItem("Consumers", 12.4));
    series.add(new DataSeriesItem("Subsidies", 1.4));
    conf.setSeries(series);
    return chart;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Tooltip(com.vaadin.addon.charts.model.Tooltip) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 43 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class AngularGauge method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.getChart().setPlotBackgroundColor(null);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(0);
    configuration.getChart().setPlotShadow(false);
    configuration.setTitle("Speedometer");
    GradientColor gradient1 = GradientColor.createLinear(0, 0, 0, 1);
    gradient1.addColorStop(0, new SolidColor("#FFF"));
    gradient1.addColorStop(1, new SolidColor("#333"));
    GradientColor gradient2 = GradientColor.createLinear(0, 0, 0, 1);
    gradient2.addColorStop(0, new SolidColor("#333"));
    gradient2.addColorStop(1, new SolidColor("#FFF"));
    Background[] background = new Background[3];
    background[0] = new Background();
    background[0].setBackgroundColor(gradient1);
    background[0].setBorderWidth(0);
    background[0].setOuterRadius("109%");
    background[1] = new Background();
    background[1].setBackgroundColor(gradient2);
    background[1].setBorderWidth(1);
    background[1].setOuterRadius("107%");
    background[2] = new Background();
    background[2].setBackgroundColor(new SolidColor("#DDD"));
    background[2].setBorderWidth(0);
    background[2].setInnerRadius("103%");
    background[2].setOuterRadius("105%");
    configuration.getPane().setStartAngle(-150);
    configuration.getPane().setEndAngle(150);
    configuration.getPane().setBackground(background);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("km/h"));
    yAxis.setMin(0);
    yAxis.setMax(200);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickWidth(1);
    yAxis.setMinorTickLength(10);
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    yAxis.setMinorTickColor(new SolidColor("#666"));
    yAxis.setGridLineWidth(0);
    yAxis.setTickPixelInterval(30);
    yAxis.setTickWidth(2);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setTickLength(10);
    yAxis.setTickColor(new SolidColor("#666"));
    Labels labels = new Labels();
    labels.setStep(2);
    labels.setRotationPerpendicular();
    yAxis.setLabels(labels);
    PlotBand[] plotBands = new PlotBand[3];
    plotBands[0] = new PlotBand(0, 120, new SolidColor("#55BF3B"));
    plotBands[1] = new PlotBand(120, 160, new SolidColor("#DDDF0D"));
    plotBands[2] = new PlotBand(160, 200, new SolidColor("#DF5353"));
    yAxis.setPlotBands(plotBands);
    final ListSeries series = new ListSeries("Speed", 80);
    PlotOptionsGauge plotOptions = new PlotOptionsGauge();
    plotOptions.setTooltip(new SeriesTooltip());
    plotOptions.getTooltip().setValueSuffix(" km/h");
    series.setPlotOptions(plotOptions);
    configuration.setSeries(series);
    runWhileAttached(chart, new Runnable() {

        Random r = new Random(0);

        @Override
        public void run() {
            Integer oldValue = series.getData()[0].intValue();
            Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
            series.updatePoint(0, newValue);
        }
    }, 3000, 12000);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) 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) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

Example 44 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class AreaRange method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREARANGE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Temperature variation by day");
    conf.getxAxis().setType(DATETIME);
    conf.getxAxis().setCrosshair(new Crosshair());
    conf.addyAxis(new YAxis());
    Tooltip tooltip = new Tooltip();
    tooltip.setShared(true);
    tooltip.setValueSuffix("°C");
    conf.setTooltip(tooltip);
    RangeSeries data = new RangeSeries("Temperatures", getRawData());
    conf.setSeries(data);
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) RangeSeries(com.vaadin.addon.charts.model.RangeSeries) Crosshair(com.vaadin.addon.charts.model.Crosshair) Tooltip(com.vaadin.addon.charts.model.Tooltip) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 45 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class LargeDataSet method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.getConfiguration().setTitle("Large data set");
    // Force zoom and enable scrollbar
    chart.getConfiguration().getxAxis().setMin(5000);
    chart.getConfiguration().getScrollbar().setEnabled(true);
    DataSeries series = new DataSeries();
    Number[] data = TimeSeriesZoomable.USD_TO_EUR_EXCHANGE_RATES;
    Random r = new Random(0);
    int x = 0;
    for (int j = 0; j < ROUNDS; j++) {
        for (Number number : data) {
            DataSeriesItem item;
            if (xyPairs()) {
                x += r.nextInt(4);
                item = new DataSeriesItem(x, number);
            } else {
                // interval data (x == index of data point), performs better
                // and consumes less memory/bandwidth
                item = new DataSeriesItem();
                item.setY(number);
            }
            /*
                 * Note, with large datasets, avoid settings like
                 * item.setColor(myColorX), or item.setName(myName) for data
                 * items. Without them the framework is able to optimize the
                 * rendering and can survive from rather large datasets.
                 * 
                 * Also note, that if data set is very large, the library might
                 * ignore it if there are custom settings for data items. This
                 * threshold is called turboThreshHold in plot options. See
                 * example below.
                 */
            // item.setName("x " + x);
            series.add(item);
        }
    }
    /*
         * If you play with this example your might try uncomment next line to
         * keep the amount of transfered data sane. You might also try to
         * increase the ROUNDS to increase the input data. By default commented
         * out to stress client side performance
         */
    // reduce(series, 1000);
    /*
         * If data can contain high/low peaks, one can use more sophisticated
         * algorithms
         */
    // ramerDouglasPeuckerReduce(series, 300);
    chart.getConfiguration().setSeries(series);
    PlotOptionsLine plotOptionsLine = new PlotOptionsLine();
    // Showing points with thousands of data items looks odd (on top of each
    // other), also renders faster without markers
    plotOptionsLine.setMarker(new Marker(false));
    // To render shadow, library must create additional element, without it
    // performance will be better
    plotOptionsLine.setShadow(false);
    plotOptionsLine.setAnimation(false);
    /*
         * If developers need to use large data sets and point specific
         * settings, they can override the default turbo threshold. Here we set
         * it to 200000 (default 1000). Turbo threshold is configuration that
         * works as a "sanity threshold" so that old browsers wont drop to their
         * knees under load. Without this Vaadin Charts might not render chart
         * if data items have e.g. name set.
         */
    plotOptionsLine.setTurboThreshold(200000);
    chart.getConfiguration().setPlotOptions(plotOptionsLine);
    return chart;
}
Also used : Random(java.util.Random) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Marker(com.vaadin.addon.charts.model.Marker) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Aggregations

Chart (com.vaadin.addon.charts.Chart)243 Configuration (com.vaadin.addon.charts.model.Configuration)196 YAxis (com.vaadin.addon.charts.model.YAxis)105 DataSeries (com.vaadin.addon.charts.model.DataSeries)81 ListSeries (com.vaadin.addon.charts.model.ListSeries)76 XAxis (com.vaadin.addon.charts.model.XAxis)71 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)57 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)55 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)50 DataLabels (com.vaadin.addon.charts.model.DataLabels)45 Tooltip (com.vaadin.addon.charts.model.Tooltip)44 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)34 Legend (com.vaadin.addon.charts.model.Legend)29 Marker (com.vaadin.addon.charts.model.Marker)23 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)21 Style (com.vaadin.addon.charts.model.style.Style)20 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)19 Labels (com.vaadin.addon.charts.model.Labels)18 VerticalLayout (com.vaadin.ui.VerticalLayout)18 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)16