Search in sources :

Example 46 with YAxis

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

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

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

the class ColumnWithLazyMultiLevelDrilldown method getChart.

@Override
protected Component getChart() {
    VerticalLayout layout = new VerticalLayout();
    final Chart chart = new Chart(ChartType.COLUMN);
    chart.setId("chart");
    conf = chart.getConfiguration();
    conf.setTitle("Global happiness index");
    conf.setSubTitle("Source: www.happyplanetindex.org");
    conf.getLegend().setEnabled(false);
    XAxis x = new XAxis();
    x.setType(AxisType.CATEGORY);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setTitle("Total");
    conf.addyAxis(y);
    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setCursor(Cursor.POINTER);
    column.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(column);
    DataSeries series = new DataSeries();
    series.setName("Regions");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColorByPoint(true);
    series.setPlotOptions(plotOptionsColumn);
    DataSeriesItem item = new DataSeriesItem("Latin America and Carribean", 60);
    item.setId("Latin America and Carribean");
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Western Nations", 50);
    item.setId("Western Nations");
    series.addItemWithDrilldown(item);
    conf.addSeries(series);
    drillSeries = new HashMap<String, DataSeries>();
    DataSeries drill = new DataSeries("Latin America and Carribean Countries");
    item = new DataSeriesItem("Costa Rica", 64);
    item.setId("Costa Rica");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Colombia", 59.8);
    item.setId("Colombia");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Belize", 59.3);
    item.setId("Belize");
    drill.addItemWithDrilldown(item);
    drillSeries.put("Latin America and Carribean", drill);
    drill = new DataSeries("Western Nations Countries");
    item = new DataSeriesItem("New Zealand", 51.6);
    item.setId("New Zealand");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Norway", 51.4);
    item.setId("Norway");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Switzerland", 50.3);
    item.setId("Switzerland");
    drill.addItemWithDrilldown(item);
    drillSeries.put("Western Nations", drill);
    drill = new DataSeries("Details Costa Rica");
    drill.setId("Details Costa Rica");
    String[] categories = new String[] { "Life Expectancy", "Well-being (0-10)", "Footprint (gha/capita)" };
    Number[] ys = new Number[] { 79.3, 7.3, 2.5 };
    drill.setData(categories, ys);
    drillSeries.put("Costa Rica", drill);
    drill = new DataSeries("Details Colombia");
    drill.setId("Details Colombia");
    ys = new Number[] { 73.7, 6.4, 1.8 };
    drill.setData(categories, ys);
    drillSeries.put("Colombia", drill);
    drill = new DataSeries("Details Belize");
    drill.setId("Details Belize");
    ys = new Number[] { 76.1, 6.5, 2.1 };
    drill.setData(categories, ys);
    drillSeries.put("Belize", drill);
    drill = new DataSeries("Details New Zealand");
    drill.setId("Details New Zealand");
    ys = new Number[] { 80.7, 7.2, 4.3 };
    drill.setData(categories, ys);
    drillSeries.put("New Zealand", drill);
    drill = new DataSeries("Details Norway");
    drill.setId("Details Norway");
    ys = new Number[] { 81.1, 7.6, 4.8 };
    drill.setData(categories, ys);
    drillSeries.put("Norway", drill);
    drill = new DataSeries("Details Switzerland");
    drill.setId("Details Switzerland");
    ys = new Number[] { 82.3, 7.5, 5.0 };
    drill.setData(categories, ys);
    drillSeries.put("Switzerland", drill);
    chart.setDrilldownCallback(new DrilldownCallback() {

        @Override
        public Series handleDrilldown(DrilldownEvent event) {
            log("DrilldownEvent: " + event.getItem().getId());
            return getPointDrilldown(event.getItem());
        }
    });
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            log("PointClickEvent: " + event.getSeries().getName() + " index :" + event.getPointIndex());
        }
    });
    chart.addChartDrillupListener(new ChartDrillupListener() {

        @Override
        public void onDrillup(ChartDrillupEvent event) {
            log("ChartDrillupEvent");
        }
    });
    layout.addComponent(chart);
    layout.addComponent(log);
    return layout;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) ChartDrillupListener(com.vaadin.addon.charts.ChartDrillupListener) XAxis(com.vaadin.addon.charts.model.XAxis) DrilldownEvent(com.vaadin.addon.charts.DrilldownEvent) Series(com.vaadin.addon.charts.model.Series) DataSeries(com.vaadin.addon.charts.model.DataSeries) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) PointClickListener(com.vaadin.addon.charts.PointClickListener) DrilldownCallback(com.vaadin.addon.charts.DrilldownCallback) VerticalLayout(com.vaadin.ui.VerticalLayout) 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) ChartDrillupEvent(com.vaadin.addon.charts.ChartDrillupEvent)

Example 49 with YAxis

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

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

the class BasicArea method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREA);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("US and USSR nuclear stockpiles"));
    conf.setSubTitle(new Subtitle("Source: <a href=\"http://thebulletin.metapress.com/content/c4120650912x74k7/fulltext.pdf\">thebulletin.metapress.com</a>"));
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setPointStart(1940);
    Marker marker = new Marker();
    marker.setEnabled(false);
    marker.setSymbol(MarkerSymbolEnum.CIRCLE);
    marker.setRadius(2);
    States states = new States();
    states.setHover(new Hover(true));
    marker.setStates(states);
    plotOptions.setMarker(marker);
    conf.setPlotOptions(plotOptions);
    XAxis xAxis = new XAxis();
    Labels labels = new Labels();
    // Display x axis value (year) as non formatted integer
    labels.setFormatter("this.value");
    xAxis.setLabels(labels);
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle(new AxisTitle("Nuclear weapon states"));
    labels = new Labels();
    // display y axis value in kilos as there is such a pile of weapons
    labels.setFormatter("this.value / 1000 +'k'");
    yAxis.setLabels(labels);
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +' produced <b>'+ Highcharts.numberFormat(this.y, 0) +'</b><br/>warheads in '+ this.x");
    conf.setTooltip(tooltip);
    final Number[] usaNumbers = new Number[] { null, null, null, null, null, 6, 11, 32, 110, 235, 369, 640, 1005, 1436, 2063, 3057, 4618, 6444, 9822, 15468, 20434, 24126, 27387, 29459, 31056, 31982, 32040, 31233, 29224, 27342, 26662, 26956, 27912, 28999, 28965, 27826, 25579, 25722, 24826, 24605, 24304, 23464, 23708, 24099, 24357, 24237, 24401, 24344, 23586, 22380, 21004, 17287, 14747, 13076, 12555, 12144, 11009, 10950, 10871, 10824, 10577, 10527, 10475, 10421, 10358, 10295, 10104 };
    conf.addSeries(new ListSeries("USA", usaNumbers));
    final Number[] ussrNumbers = new Number[] { null, null, null, null, null, null, null, null, null, null, 5, 25, 50, 120, 150, 200, 426, 660, 869, 1060, 1605, 2471, 3322, 4238, 5221, 6129, 7089, 8339, 9399, 10538, 11643, 13092, 14478, 15915, 17385, 19055, 21205, 23044, 25393, 27935, 30062, 32049, 33952, 35804, 37431, 39197, 45000, 43000, 41000, 39000, 37000, 35000, 33000, 31000, 29000, 27000, 25000, 24000, 23000, 22000, 21000, 20000, 19000, 18000, 18000, 17000, 16000 };
    conf.addSeries(new ListSeries("USSR/Russia", ussrNumbers));
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Tooltip(com.vaadin.addon.charts.model.Tooltip) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) Labels(com.vaadin.addon.charts.model.Labels) Marker(com.vaadin.addon.charts.model.Marker) XAxis(com.vaadin.addon.charts.model.XAxis) States(com.vaadin.addon.charts.model.States) Subtitle(com.vaadin.addon.charts.model.Subtitle) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

YAxis (com.vaadin.addon.charts.model.YAxis)115 Chart (com.vaadin.addon.charts.Chart)105 Configuration (com.vaadin.addon.charts.model.Configuration)100 XAxis (com.vaadin.addon.charts.model.XAxis)63 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)51 ListSeries (com.vaadin.addon.charts.model.ListSeries)46 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)40 DataSeries (com.vaadin.addon.charts.model.DataSeries)39 Tooltip (com.vaadin.addon.charts.model.Tooltip)39 DataLabels (com.vaadin.addon.charts.model.DataLabels)30 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)28 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)27 Legend (com.vaadin.addon.charts.model.Legend)24 Labels (com.vaadin.addon.charts.model.Labels)19 Marker (com.vaadin.addon.charts.model.Marker)16 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)14 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)13 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)13 Title (com.vaadin.addon.charts.model.Title)13 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)13