Search in sources :

Example 46 with DataLabels

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

the class BasicLineWithRedGridLines 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.MIDDLE);
    yAxis.setGridLineColor(new SolidColor("red"));
    yAxis.setGridLineDashStyle(DashStyle.DASHDOT);
    yAxis.setGridLineWidth(3);
    XAxis xAxis = configuration.getxAxis();
    xAxis.setGridLineColor(new SolidColor(0, 255, 0, 0.5));
    xAxis.setGridLineWidth(4);
    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);
    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 : 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) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) 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 47 with DataLabels

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

the class Clock method getChart.

@Override
protected Chart getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");
    chart.setHeight("200px");
    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("The Vaadin Charts clock");
    configuration.getCredits().setEnabled(false);
    GradientColor gradient1 = GradientColor.createRadial(0.5, -0.4, 1.9);
    gradient1.addColorStop(0.5, new SolidColor(255, 255, 255, 0.2));
    gradient1.addColorStop(0.5, new SolidColor(200, 200, 200, 0.2));
    Background[] background = new Background[2];
    background[0] = new Background();
    background[1] = new Background();
    background[1].setBackgroundColor(gradient1);
    background[1].setBorderWidth(1);
    background[1].setOuterRadius("107%");
    configuration.getPane().setBackground(background);
    YAxis yAxis = configuration.getyAxis();
    Labels labels = new Labels();
    labels.setDistance(-20);
    yAxis.setLabels(labels);
    yAxis.setMin(0);
    yAxis.setMax(12);
    yAxis.setLineWidth(0);
    yAxis.setShowFirstLabel(false);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickWidth(1);
    yAxis.setMinorTickLength(5);
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    yAxis.setMinorGridLineWidth(0);
    yAxis.setMinorTickColor(new SolidColor("#666"));
    yAxis.setTickInterval(1);
    yAxis.setTickWidth(2);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setTickLength(10);
    yAxis.setTickColor(new SolidColor("#666"));
    yAxis.setTitle(new AxisTitle("Powered by<br/>Vaadin Charts"));
    yAxis.getTitle().setStyle(new Style());
    yAxis.getTitle().getStyle().setColor(new SolidColor("#BBB"));
    yAxis.getTitle().getStyle().setFontWeight(FontWeight.BOLD);
    yAxis.getTitle().getStyle().setFontSize("8px");
    yAxis.getTitle().getStyle().setLineHeight("10px");
    yAxis.getTitle().setY(10);
    final DataSeries series = new DataSeries();
    final DataSeriesItem hour = new DataSeriesItem();
    final DataSeriesItem minute = new DataSeriesItem();
    final DataSeriesItem second = new DataSeriesItem();
    hour.setId("hour");
    hour.setY(10);
    hour.setDial(new Dial());
    hour.getDial().setRadius("60%");
    hour.getDial().setBaseWidth(4);
    hour.getDial().setRearLength("0%");
    hour.getDial().setBaseLength("95%");
    minute.setId("minute");
    minute.setY(10);
    minute.setDial(new Dial());
    minute.getDial().setBaseLength("95%");
    minute.getDial().setRearLength("0%");
    second.setId("second");
    second.setY(30);
    second.setDial(new Dial());
    second.getDial().setRadius("100%");
    second.getDial().setBaseWidth(1);
    second.getDial().setRearLength("20%");
    series.add(hour);
    series.add(minute);
    series.add(second);
    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    plotOptionsGauge.setDataLabels(new DataLabels(false));
    configuration.setPlotOptions(plotOptionsGauge);
    configuration.setSeries(series);
    final Calendar cal = Calendar.getInstance();
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            cal.setTimeInMillis(System.currentTimeMillis());
            double hours = cal.get(Calendar.HOUR);
            double mins = cal.get(Calendar.MINUTE);
            double secs = cal.get(Calendar.SECOND);
            // disable animation when the second dial reaches 0
            boolean animation = secs == 0 ? false : true;
            configuration.getChart().setAnimation(animation);
            hour.setY(hours + (mins / 60.0));
            minute.setY(mins * (12.0 / 60.0) + secs * (12.0 / 3600.0));
            second.setY(secs * (12.0 / 60.0));
            series.update(hour);
            series.update(minute);
            series.update(second);
        }
    }, 1000, 15000);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) Calendar(java.util.Calendar) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Dial(com.vaadin.addon.charts.model.Dial) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Style(com.vaadin.addon.charts.model.style.Style) 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 48 with DataLabels

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

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

the class ChartTypes method chartTypesTreemap.

public void chartTypesTreemap() {
    Chart chart = new Chart();
    PlotOptionsTreemap plotOptions = new PlotOptionsTreemap();
    plotOptions.setLayoutAlgorithm(TreeMapLayoutAlgorithm.STRIPES);
    plotOptions.setAlternateStartingDirection(true);
    Level level = new Level();
    level.setLevel(1);
    level.setLayoutAlgorithm(TreeMapLayoutAlgorithm.SLICEANDDICE);
    DataLabels dataLabels = new DataLabels();
    dataLabels.setEnabled(true);
    dataLabels.setAlign(HorizontalAlign.LEFT);
    dataLabels.setVerticalAlign(VerticalAlign.TOP);
    Style style = new Style();
    style.setFontSize("15px");
    style.setFontWeight(FontWeight.BOLD);
    dataLabels.setStyle(style);
    level.setDataLabels(dataLabels);
    plotOptions.setLevels(level);
    TreeSeries series = new TreeSeries();
    TreeSeriesItem apples = new TreeSeriesItem("A", "Apples");
    apples.setColor(new SolidColor("#EC2500"));
    TreeSeriesItem bananas = new TreeSeriesItem("B", "Bananas");
    bananas.setColor(new SolidColor("#ECE100"));
    TreeSeriesItem oranges = new TreeSeriesItem("O", "Oranges");
    oranges.setColor(new SolidColor("#EC9800"));
    TreeSeriesItem anneA = new TreeSeriesItem("Anne", apples, 5);
    TreeSeriesItem rickA = new TreeSeriesItem("Rick", apples, 3);
    TreeSeriesItem paulA = new TreeSeriesItem("Paul", apples, 4);
    TreeSeriesItem anneB = new TreeSeriesItem("Anne", bananas, 4);
    TreeSeriesItem rickB = new TreeSeriesItem("Rick", bananas, 10);
    TreeSeriesItem paulB = new TreeSeriesItem("Paul", bananas, 1);
    TreeSeriesItem anneO = new TreeSeriesItem("Anne", oranges, 1);
    TreeSeriesItem rickO = new TreeSeriesItem("Rick", oranges, 3);
    TreeSeriesItem paulO = new TreeSeriesItem("Paul", oranges, 3);
    TreeSeriesItem susanne = new TreeSeriesItem("Susanne", 2);
    susanne.setParent("Kiwi");
    susanne.setColor(new SolidColor("#9EDE00"));
    series.addAll(apples, bananas, oranges, anneA, rickA, paulA, anneB, rickB, paulB, anneO, rickO, paulO, susanne);
    series.setPlotOptions(plotOptions);
    chart.getConfiguration().addSeries(series);
    chart.getConfiguration().setTitle("Fruit consumption");
}
Also used : TreeSeries(com.vaadin.addon.charts.model.TreeSeries) DataLabels(com.vaadin.addon.charts.model.DataLabels) PlotOptionsTreemap(com.vaadin.addon.charts.model.PlotOptionsTreemap) DashStyle(com.vaadin.addon.charts.model.DashStyle) Style(com.vaadin.addon.charts.model.style.Style) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Level(com.vaadin.addon.charts.model.Level) TreeSeriesItem(com.vaadin.addon.charts.model.TreeSeriesItem) Chart(com.vaadin.addon.charts.Chart)

Example 50 with DataLabels

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

the class ChartTypes method chartTypesHeatMap.

public void chartTypesHeatMap() {
    Chart chart = new Chart(ChartType.HEATMAP);
    chart.setWidth("600px");
    chart.setHeight("300px");
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Heat Data");
    // Set colors for the extremes
    conf.getColorAxis().setMinColor(SolidColor.AQUA);
    conf.getColorAxis().setMaxColor(SolidColor.RED);
    // Set up border and data labels
    PlotOptionsHeatmap plotOptions = new PlotOptionsHeatmap();
    plotOptions.setBorderColor(SolidColor.WHITE);
    plotOptions.setBorderWidth(2);
    plotOptions.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(plotOptions);
    // Create some data
    HeatSeries series = new HeatSeries();
    // Jan High
    series.addHeatPoint(0, 0, 10.9);
    // Jan Low
    series.addHeatPoint(0, 1, -51.5);
    // Feb High
    series.addHeatPoint(1, 0, 11.8);
    // Dec Low
    series.addHeatPoint(11, 1, -47.0);
    conf.addSeries(series);
    // Set the category labels on the X axis
    XAxis xaxis = new XAxis();
    xaxis.setTitle("Month");
    xaxis.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(xaxis);
    // Set the category labels on the Y axis
    YAxis yaxis = new YAxis();
    yaxis.setTitle("");
    yaxis.setCategories("High C", "Low C");
    conf.addyAxis(yaxis);
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) HeatSeries(com.vaadin.addon.charts.model.HeatSeries) PlotOptionsHeatmap(com.vaadin.addon.charts.model.PlotOptionsHeatmap) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

DataLabels (com.vaadin.addon.charts.model.DataLabels)51 Chart (com.vaadin.addon.charts.Chart)45 Configuration (com.vaadin.addon.charts.model.Configuration)41 YAxis (com.vaadin.addon.charts.model.YAxis)30 DataSeries (com.vaadin.addon.charts.model.DataSeries)22 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)19 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)18 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)17 ListSeries (com.vaadin.addon.charts.model.ListSeries)17 XAxis (com.vaadin.addon.charts.model.XAxis)16 Tooltip (com.vaadin.addon.charts.model.Tooltip)13 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)12 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)11 Style (com.vaadin.addon.charts.model.style.Style)11 Legend (com.vaadin.addon.charts.model.Legend)9 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)9 Labels (com.vaadin.addon.charts.model.Labels)6 Series (com.vaadin.addon.charts.model.Series)6 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)6 DrilldownCallback (com.vaadin.addon.charts.DrilldownCallback)4