Search in sources :

Example 16 with ListSeries

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

the class CustomThemeUI method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    ChartOptions.get().setTheme(new CustomTheme());
    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(new String[] { "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.MIDDLE);
    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);
    ListSeries ls = new ListSeries();
    ls.setName("Tokyo");
    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);
    chart.drawChart(configuration);
    return chart;
}
Also used : 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) CustomTheme(com.vaadin.addon.charts.examples.themes.CustomTheme) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 17 with ListSeries

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

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

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

the class LineWithDashSelector method getChart.

@Override
protected Component getChart() {
    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.MIDDLE);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    plotOptions.setDashStyle(DashStyle.DOT);
    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);
    ListSeries ls = new ListSeries();
    ls.setName("Tokyo");
    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("New York");
    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 20 with ListSeries

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

the class LinesWithComplexHtmlTooltip method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Tooltip tooltip = new Tooltip();
    tooltip.setShared(true);
    tooltip.setUseHTML(true);
    tooltip.setHeaderFormat("<small>{point.key}</small><table>");
    tooltip.setPointFormat("<tr><td style=\"color: {series.color}\">{series.name}: </td><td style=\"text-align: right\"><b>{point.y} EUR</b></td></tr>");
    tooltip.setFooterFormat("</table>");
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Complex tooltip");
    configuration.setTooltip(tooltip);
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    ListSeries ls = new ListSeries();
    ls.setName("Short");
    ls.setData(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Long named series");
    Number[] data = new Number[] { 129.9, 171.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 195.6, 154.4 };
    for (int i = 0; i < data.length / 2; i++) {
        Number number = data[i];
        data[i] = data[data.length - i - 1];
        data[data.length - i - 1] = number;
    }
    ls.setData(data);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    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)

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