Search in sources :

Example 41 with ListSeries

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

the class ToggledSeriesVisibility method getChart.

@Override
protected Component getChart() {
    chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Monthly Average Rainfall");
    conf.setSubTitle("Source: WorldClimate.com");
    XAxis x = new XAxis();
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    conf.addyAxis(y);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(100);
    legend.setY(70);
    legend.setFloating(true);
    legend.setShadow(true);
    conf.setLegend(legend);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.x +': '+ this.y +' mm'");
    conf.setTooltip(tooltip);
    PlotOptionsColumn plot = new PlotOptionsColumn();
    plot.setPointPadding(0.2);
    plot.setBorderWidth(0);
    conf.addSeries(tokyo);
    conf.addSeries(newYork);
    conf.addSeries(berlin);
    conf.addSeries(london);
    chart.addLegendItemClickListener(new LegendItemClickListener() {

        @Override
        public void onClick(LegendItemClickEvent event) {
            /*
                 * Visibility of the series is also toggled from legend clicks
                 * by default. Still developers might wish to override this
                 * behavior if the visibility is also controlled by other
                 * components like here or if e.g. multiple charts are bound
                 * together (hiding series in one chart should hide related data
                 * in other chart as well).
                 */
            ListSeries series = (ListSeries) event.getSeries();
            /*
                 * Toggle checked in option group. As a side effect (via value
                 * change listener, see setup method) the visibility will change
                 * in the chart as well.
                 */
            if (series.isVisible()) {
                checkBoxGroup.deselect(series);
            } else {
                checkBoxGroup.select(series);
            }
        }
    });
    chart.drawChart(conf);
    return chart;
}
Also used : LegendItemClickListener(com.vaadin.addon.charts.LegendItemClickListener) Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) LegendItemClickEvent(com.vaadin.addon.charts.LegendItemClickEvent) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 42 with ListSeries

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

the class ScatterWithRegressionLine method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    Color[] colors = getThemeColors();
    XAxis x = new XAxis();
    x.setMin(-0.5);
    x.setMax(5.5);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    conf.addyAxis(y);
    conf.setTitle("Scatter plot with regression line");
    DataSeries series = new DataSeries();
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setColor(colors[1]);
    series.setPlotOptions(plotOptions);
    series.setName("Regression Line");
    List<DataSeriesItem> list = new ArrayList<DataSeriesItem>();
    list.add(new DataSeriesItem(0, 1.11));
    list.add(new DataSeriesItem(5, 4.51));
    series.setData(list);
    plotOptions.setMarker(new Marker(true));
    plotOptions.setEnableMouseTracking(true);
    Hover hover = new Hover();
    hover.setLineWidth(0);
    States states = new States();
    states.setHover(hover);
    plotOptions.setStates(states);
    conf.addSeries(series);
    ListSeries listSeries = new ListSeries("Observations", 1, 1.5, 2.8, 3.5, 3.9, 4.2);
    PlotOptionsScatter plotOptions2 = new PlotOptionsScatter();
    listSeries.setPlotOptions(plotOptions2);
    Marker marker = new Marker(true);
    marker.setRadius(4);
    plotOptions2.setMarker(marker);
    conf.addSeries(listSeries);
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsScatter(com.vaadin.addon.charts.model.PlotOptionsScatter) Color(com.vaadin.addon.charts.model.style.Color) ArrayList(java.util.ArrayList) Marker(com.vaadin.addon.charts.model.Marker) XAxis(com.vaadin.addon.charts.model.XAxis) States(com.vaadin.addon.charts.model.States) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 43 with ListSeries

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

the class ColumnWithShapedLabels method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Stacked column chart"));
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" });
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    yAxis.setTitle(new AxisTitle("Total fruit consumption"));
    conf.addyAxis(yAxis);
    PlotOptionsColumn plotOptions = new PlotOptionsColumn();
    plotOptions.setStacking(Stacking.NORMAL);
    DataLabels labels = new DataLabels(true);
    labels.setBackgroundColor(SolidColor.BURLYWOOD);
    labels.setColor(new SolidColor("white"));
    labels.setShape(Shape.DIAMOND);
    Style style = new Style();
    style.setTextShadow("0 0 3px black");
    labels.setStyle(style);
    plotOptions.setDataLabels(labels);
    conf.setPlotOptions(plotOptions);
    conf.addSeries(new ListSeries("John", new Number[] { 5, 3, 4, 7, 2 }));
    conf.addSeries(new ListSeries("Jane", new Number[] { 2, 2, 3, 2, 1 }));
    conf.addSeries(new ListSeries("Joe", new Number[] { 3, 4, 4, 2, 5 }));
    chart.drawChart(conf);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Style(com.vaadin.addon.charts.model.style.Style) 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 44 with ListSeries

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

the class StackedAndGroupedColumn method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Total fruit consumption, grouped by gender"));
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" });
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setAllowDecimals(false);
    yAxis.setMin(0);
    yAxis.setTitle(new AxisTitle("Number of fruits"));
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("function() { return '<b>'+ this.x +'</b><br/>'" + "+this.series.name +': '+ this.y +'<br/>'+'Total: '+ this.point.stackTotal; }");
    conf.setTooltip(tooltip);
    PlotOptionsColumn plotOptions = new PlotOptionsColumn();
    plotOptions.setStacking(Stacking.NORMAL);
    conf.setPlotOptions(plotOptions);
    ListSeries serie = new ListSeries("John", new Number[] { 5, 3, 4, 7, 2 });
    serie.setStack("male");
    conf.addSeries(serie);
    serie = new ListSeries("Joe", new Number[] { 3, 4, 4, 2, 5 });
    serie.setStack("male");
    conf.addSeries(serie);
    serie = new ListSeries("Jane", new Number[] { 2, 5, 6, 2, 1 });
    serie.setStack("female");
    conf.addSeries(serie);
    serie = new ListSeries("Janet", new Number[] { 3, 0, 4, 4, 3 });
    serie.setStack("female");
    conf.addSeries(serie);
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) 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 45 with ListSeries

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

the class StackedBar method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.BAR);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Stacked bar chart");
    XAxis x = new XAxis();
    x.setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Total fruit consumption");
    conf.addyAxis(y);
    Legend legend = new Legend();
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    legend.setReversed(true);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +': '+ this.y");
    conf.setTooltip(tooltip);
    PlotOptionsSeries plot = new PlotOptionsSeries();
    plot.setStacking(Stacking.NORMAL);
    conf.setPlotOptions(plot);
    conf.addSeries(new ListSeries("John", 5, 3, 4, 7, 2));
    conf.addSeries(new ListSeries("Jane", 2, 2, 3, 2, 1));
    conf.addSeries(new ListSeries("Joe", 3, 4, 4, 2, 5));
    chart.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

ListSeries (com.vaadin.addon.charts.model.ListSeries)88 Chart (com.vaadin.addon.charts.Chart)76 Configuration (com.vaadin.addon.charts.model.Configuration)70 YAxis (com.vaadin.addon.charts.model.YAxis)46 XAxis (com.vaadin.addon.charts.model.XAxis)35 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)31 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)25 Tooltip (com.vaadin.addon.charts.model.Tooltip)24 Legend (com.vaadin.addon.charts.model.Legend)18 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)18 DataLabels (com.vaadin.addon.charts.model.DataLabels)17 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)16 Title (com.vaadin.addon.charts.model.Title)15 Labels (com.vaadin.addon.charts.model.Labels)11 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)11 Marker (com.vaadin.addon.charts.model.Marker)10 VerticalLayout (com.vaadin.ui.VerticalLayout)9 Hover (com.vaadin.addon.charts.model.Hover)8 States (com.vaadin.addon.charts.model.States)8 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)8