Search in sources :

Example 31 with Legend

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

the class SplineInverted method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setWidth("500px");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getChart().setInverted(true);
    configuration.getTitle().setText("Atmosphere Temperature by Altitude");
    configuration.getSubTitle().setText("According to the Standard Atmosphere Model");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setReversed(false);
    xAxis.setTitle(new AxisTitle("Altitude"));
    Labels labels = new Labels();
    labels.setFormatter("this.value + 'km'");
    labels.setEnabled(true);
    xAxis.setLabels(labels);
    xAxis.setMaxPadding(0.05);
    xAxis.setShowLastLabel(true);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setLineWidth(2);
    yAxis.setTitle(new AxisTitle("Temperature"));
    yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
    Labels labelsy = new Labels();
    labelsy.setEnabled(true);
    labelsy.setFormatter("this.value + '°'");
    yAxis.setLabels(labelsy);
    configuration.getTooltip().setFormatter("this.x +' km: '+this.y +'°C'");
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    plotOptions.setMarker(new Marker(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setEnabled(false);
    DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Temperature");
    series.addData(new Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }, { 30, -46.5 }, { 40, -22.1 }, { 50, -2.5 }, { 60, -27.7 }, { 70, -55.7 }, { 80, -76.5 } });
    configuration.setSeries(series);
    chart.drawChart(configuration);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) Labels(com.vaadin.addon.charts.model.Labels) 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) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 32 with Legend

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

the class LegendMarginTestUI method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.LINE);
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.getConfiguration().addSeries(new ListSeries(1, 2, 3));
    Legend legend = chart.getConfiguration().getLegend();
    legend.setMargin(100);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) ListSeries(com.vaadin.addon.charts.model.ListSeries) Chart(com.vaadin.addon.charts.Chart)

Example 33 with Legend

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

the class BasicLineWithHTMLLegend 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().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setMin(-5d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.HIGH);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setUseHTML(true);
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-10d);
    legend.setY(100d);
    legend.setBorderWidth(0);
    ListSeries ls = new ListSeries();
    ls.setName("<i>Tokyo</i>");
    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("<span style='font-family:serif;'>New York</span>");
    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);
    ls = new ListSeries();
    ls.setName("Berlin");
    ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
    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 : Legend(com.vaadin.addon.charts.model.Legend) 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)

Example 34 with Legend

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

the class LineWithMissingPoint 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().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setMin(-5d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.HIGH);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-10d);
    legend.setY(100d);
    legend.setBorderWidth(0);
    DataSeries ds = new DataSeries();
    DataSeriesItem item = new DataSeriesItem(1, 2);
    item.setName("a");
    ds.add(item);
    item = new DataSeriesItem(2, 2);
    item.setName("b");
    ds.add(item);
    item = new DataSeriesItem(3, 2);
    item.setName("c");
    ds.add(item);
    item = new DataSeriesItem(4, null);
    item.setName("d");
    ds.add(item);
    item = new DataSeriesItem(5, 2);
    item.setName("e");
    ds.add(item);
    item = new DataSeriesItem(6, 2);
    item.setName("f");
    ds.add(item);
    configuration.addSeries(ds);
    chart.drawChart(configuration);
    System.out.println(configuration);
    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) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) 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 35 with Legend

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

the class BoxPlotExample method getChart.

@Override
protected Component getChart() {
    chart = new Chart();
    chart.getConfiguration().setTitle("Box Plot Example");
    Legend legend = new Legend();
    legend.setEnabled(false);
    chart.getConfiguration().setLegend(legend);
    XAxis xaxis = chart.getConfiguration().getxAxis();
    xaxis.setTitle("Experiment No.");
    xaxis.setCategories("1", "2", "3", "4", "5");
    YAxis yAxis = chart.getConfiguration().getyAxis();
    yAxis.setTitle("Observations");
    PlotLine plotLine = new PlotLine();
    plotLine.setColor(new SolidColor("red"));
    plotLine.setValue(932);
    plotLine.setWidth(1);
    plotLine.setZIndex(0);
    plotLine.setDashStyle(DashStyle.DASHDOT);
    Label label = new Label("Theoretical mean: 932");
    label.setAlign(HorizontalAlign.CENTER);
    Style style = new Style();
    style.setColor(new SolidColor("gray"));
    label.setStyle(style);
    plotLine.setLabel(label);
    PlotLine plotLine2 = new PlotLine();
    plotLine2.setColor(new SolidColor("blue"));
    plotLine2.setValue(800);
    plotLine2.setWidth(1);
    plotLine2.setZIndex(500);
    plotLine2.setDashStyle(DashStyle.SHORTDASHDOTDOT);
    Label label2 = new Label("Second plotline: 800");
    label2.setAlign(HorizontalAlign.CENTER);
    Style style2 = new Style();
    style2.setColor(new SolidColor("gray"));
    label2.setStyle(style2);
    plotLine2.setLabel(label2);
    yAxis.setPlotLines(plotLine, plotLine2);
    observations = new DataSeries();
    observations.setName("Observations");
    // Add PlotBoxItems contain all fields relevant for plot box chart
    observations.add(new BoxPlotItem(760, 801, 848, 895, 965));
    // Example with no arg constructor
    BoxPlotItem plotBoxItem = new BoxPlotItem();
    plotBoxItem.setLow(733);
    plotBoxItem.setLowerQuartile(853);
    plotBoxItem.setMedian(939);
    plotBoxItem.setUpperQuartile(980);
    plotBoxItem.setHigh(1080);
    observations.add(plotBoxItem);
    observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
    observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
    observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
    observations.setPlotOptions(getPlotBoxOptions());
    chart.getConfiguration().addSeries(observations);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Label(com.vaadin.addon.charts.model.Label) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DashStyle(com.vaadin.addon.charts.model.DashStyle) Style(com.vaadin.addon.charts.model.style.Style) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis) BoxPlotItem(com.vaadin.addon.charts.model.BoxPlotItem)

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