Search in sources :

Example 11 with Legend

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

the class Sparkline method configureAsSparkline.

protected void configureAsSparkline() {
    getConfiguration().setTitle("");
    getConfiguration().setLegend(new Legend(false));
    getConfiguration().getChart().setBackgroundColor(new SolidColor(0, 0, 0, 0));
    getConfiguration().getChart().setMargin(0);
    Series series = getConfiguration().getSeries().get(0);
    PlotOptionsLine options = new PlotOptionsLine();
    options.setEnableMouseTracking(false);
    options.setMarker(new Marker(false));
    options.setShowInLegend(false);
    options.setAnimation(false);
    options.setShadow(false);
    series.setPlotOptions(options);
    configureXAxis(getConfiguration().getxAxis());
    configureYAxis(getConfiguration().getyAxis());
}
Also used : ListSeries(com.vaadin.addon.charts.model.ListSeries) Series(com.vaadin.addon.charts.model.Series) Legend(com.vaadin.addon.charts.model.Legend) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Marker(com.vaadin.addon.charts.model.Marker)

Example 12 with Legend

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

the class BasicBarNoTitle method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.BAR);
    Configuration conf = chart.getConfiguration();
    conf.getTitle().setText(null);
    XAxis x = new XAxis();
    x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
    x.setTitle((String) null);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    AxisTitle title = new AxisTitle("Population (millions)");
    title.setAlign(VerticalAlign.MIDDLE);
    y.setTitle(title);
    conf.addyAxis(y);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
    conf.setTooltip(tooltip);
    PlotOptionsBar plot = new PlotOptionsBar();
    plot.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(plot);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-100);
    legend.setY(100);
    legend.setFloating(true);
    legend.setBorderWidth(1);
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    legend.setShadow(true);
    conf.setLegend(legend);
    conf.disableCredits();
    List<Series> series = new ArrayList<Series>();
    series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
    series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
    series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
    conf.setSeries(series);
    chart.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Tooltip(com.vaadin.addon.charts.model.Tooltip) ArrayList(java.util.ArrayList) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotOptionsBar(com.vaadin.addon.charts.model.PlotOptionsBar) XAxis(com.vaadin.addon.charts.model.XAxis) Series(com.vaadin.addon.charts.model.Series) ListSeries(com.vaadin.addon.charts.model.ListSeries) 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)

Example 13 with Legend

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

the class BasicColumn method getChart.

@Override
protected Component getChart() {
    Chart 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(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
    conf.addSeries(new ListSeries("New York", 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3));
    conf.addSeries(new ListSeries("London", 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2));
    conf.addSeries(new ListSeries("Berlin", 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1));
    chart.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) 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) 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 14 with Legend

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

the class AreaSpline method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREASPLINE);
    chart.setHeight("450px");
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Average fruit consumption during one week"));
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(150);
    legend.setY(100);
    conf.setLegend(legend);
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" });
    // add blue background for the weekend
    PlotBand plotBand = new PlotBand(4.5, 6.5, LIGHT_BLUE);
    plotBand.setZIndex(1);
    xAxis.setPlotBands(plotBand);
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle(new AxisTitle("Fruit units"));
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    // Customize tooltip formatting
    tooltip.setHeaderFormat("");
    tooltip.setPointFormat("{series.name}: {point.y} units");
    // Same could be achieved by defining following JS formatter funtion:
    // tooltip.setFormatter("function(){ return this.x +': '+ this.y +' units';}");
    // ... or its shorthand form:
    // tooltip.setFormatter("this.x +': '+ this.y +' units'");
    conf.setTooltip(tooltip);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setFillOpacity(0.5);
    conf.setPlotOptions(plotOptions);
    ListSeries o = new ListSeries("John", 3, 4, 3, 5, 4, 10);
    // Add last value separately
    o.addData(12);
    conf.addSeries(o);
    conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));
    chart.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) 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) PlotBand(com.vaadin.addon.charts.model.PlotBand) 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 15 with Legend

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

the class AreaWithMissingPoints method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREA);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setSpacingBottom(30);
    conf.setTitle(new Title("Fruit consumption *"));
    Subtitle subTitle = new Subtitle("* Jane\'s banana consumption is unknown");
    subTitle.setFloating(true);
    subTitle.setY(15);
    subTitle.setAlign(HorizontalAlign.RIGHT);
    subTitle.setVerticalAlign(VerticalAlign.BOTTOM);
    conf.setSubTitle(subTitle);
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Apples", "Pears", "Oranges", "Bananas", "Grapes", "Plums", "Strawberries", "Raspberries");
    conf.addxAxis(xAxis);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(150);
    legend.setY(100);
    legend.setBorderWidth(1);
    legend.setBackgroundColor(new SolidColor("#ffffff"));
    conf.setLegend(legend);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setFillOpacity(0.5);
    conf.setPlotOptions(plotOptions);
    conf.addSeries(new ListSeries("John", 0, 1, 4, 4, 5, 2, 3, 7));
    conf.addSeries(new ListSeries("Jane", 1, 0, 3, null, 3, 1, 2, 1));
    chart.drawChart(conf);
    return chart;
}
Also used : Subtitle(com.vaadin.addon.charts.model.Subtitle) Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Title(com.vaadin.addon.charts.model.Title) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis)

Aggregations

Legend (com.vaadin.addon.charts.model.Legend)35 Configuration (com.vaadin.addon.charts.model.Configuration)30 Chart (com.vaadin.addon.charts.Chart)29 YAxis (com.vaadin.addon.charts.model.YAxis)24 XAxis (com.vaadin.addon.charts.model.XAxis)20 ListSeries (com.vaadin.addon.charts.model.ListSeries)19 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)17 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)15 Tooltip (com.vaadin.addon.charts.model.Tooltip)14 DataSeries (com.vaadin.addon.charts.model.DataSeries)10 DataLabels (com.vaadin.addon.charts.model.DataLabels)9 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)8 Style (com.vaadin.addon.charts.model.style.Style)7 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)6 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)5 Series (com.vaadin.addon.charts.model.Series)5 Title (com.vaadin.addon.charts.model.Title)5 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)4 ArrayList (java.util.ArrayList)4 Labels (com.vaadin.addon.charts.model.Labels)3