Search in sources :

Example 6 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class WindRose method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setPolar(true);
    conf.getChart().setInverted(false);
    conf.setTitle("Wind rose for South Shore Met Station, Oregon");
    conf.setSubTitle("Source: or.water.usgs.gov");
    Pane pane = new Pane();
    pane.setSize("85%");
    conf.addPane(pane);
    conf.getLegend().setReversed(false);
    conf.getLegend().setAlign(HorizontalAlign.RIGHT);
    conf.getLegend().setVerticalAlign(VerticalAlign.TOP);
    conf.getLegend().setY(100);
    conf.getLegend().setLayout(LayoutDirection.VERTICAL);
    XAxis axis = new XAxis();
    axis.setCategories("< 0.5 m/s", "0.5-2 m/s", "2-4 m/s", "4-6 m/s", "6-8 m/s", "8-10 m/s", "> 10 m/s");
    axis.setTickmarkPlacement(TickmarkPlacement.ON);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    yAxis.setEndOnTick(false);
    yAxis.setShowLastLabel(true);
    yAxis.setTitle(new AxisTitle("Frequency (%)"));
    Labels labels = new Labels();
    labels.setFormatter("function() {return this.value + '%';}");
    yAxis.setLabels(labels);
    conf.addxAxis(axis);
    conf.addyAxis(yAxis);
    conf.getTooltip().setValueSuffix("%");
    PlotOptionsColumn series = new PlotOptionsColumn();
    series.setStacking(Stacking.NORMAL);
    series.setShadow(false);
    series.setGroupPadding(0);
    series.setPointPlacement(PointPlacement.ON);
    conf.setPlotOptions(series);
    ListSeries n = new ListSeries("N", 1.81, 1.78, 0.16, 0.00, 0.00, 0.00, 0.00);
    ListSeries nne = new ListSeries("NNE", 0.62, 1.09, 0.00, 0.00, 0.00, 0.00, 0.00);
    ListSeries ne = new ListSeries("NE", 0.82, 0.82, 0.07, 0.00, 0.00, 0.00, 0.00);
    ListSeries ene = new ListSeries("ENE", 0.59, 1.22, 0.07, 0.00, 0.00, 0.00, 0.00);
    ListSeries e = new ListSeries("E", 0.62, 2.20, 0.49, 0.00, 0.00, 0.00, 0.00);
    ListSeries ese = new ListSeries("ESE", 1.22, 2.01, 1.55, 0.30, 0.13, 0.00, 0.00);
    ListSeries se = new ListSeries("SE", 1.61, 3.06, 2.37, 2.14, 1.74, 0.39, 0.13);
    ListSeries sse = new ListSeries("SSE", 2.04, 3.42, 1.97, 0.86, 0.53, 0.49, 0.00);
    ListSeries s = new ListSeries("S", 2.66, 4.74, 0.43, 0.00, 0.00, 0.00, 0.00);
    ListSeries ssw = new ListSeries("SSW", 2.96, 4.14, 0.26, 0.00, 0.00, 0.00, 0.00);
    ListSeries sw = new ListSeries("SW", 2.53, 4.01, 1.22, 0.49, 0.13, 0.00, 0.00);
    ListSeries wsw = new ListSeries("WSW", 1.97, 2.66, 1.97, 0.79, 0.30, 0.00, 0.00);
    ListSeries w = new ListSeries("W", 1.64, 1.71, 0.92, 1.45, 0.26, 0.10, 0.00);
    ListSeries wnw = new ListSeries("WNW", 1.32, 2.40, 0.99, 1.61, 0.33, 0.00, 0.00);
    ListSeries nw = new ListSeries("NW", 1.58, 4.28, 1.28, 0.76, 0.66, 0.69, 0.03);
    ListSeries nnw = new ListSeries("NNW", 1.51, 5.00, 1.32, 0.13, 0.23, 0.13, 0.07);
    conf.setSeries(n, nne, ne, ene, e, ese, se, sse, s, ssw, sw, wsw, w, wnw, nw, nnw);
    // transpose data "matrix"
    conf.reverseListSeries();
    chart.drawChart(conf);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) Labels(com.vaadin.addon.charts.model.Labels) Pane(com.vaadin.addon.charts.model.Pane) 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 7 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class DonutChart method createChart.

public static Chart createChart() {
    rand = new Random(0);
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market share, April, 2011");
    YAxis yaxis = new YAxis();
    yaxis.setTitle("Total percent market share");
    PlotOptionsPie pie = new PlotOptionsPie();
    pie.setShadow(false);
    conf.setPlotOptions(pie);
    conf.getTooltip().setValueSuffix("%");
    DataSeries innerSeries = new DataSeries();
    innerSeries.setName("Browsers");
    PlotOptionsPie innerPieOptions = new PlotOptionsPie();
    innerSeries.setPlotOptions(innerPieOptions);
    innerPieOptions.setSize("237px");
    innerPieOptions.setDataLabels(new DataLabels());
    innerPieOptions.getDataLabels().setFormatter("this.y > 5 ? this.point.name : null");
    innerPieOptions.getDataLabels().setColor(new SolidColor(255, 255, 255));
    innerPieOptions.getDataLabels().setDistance(-30);
    Color[] innerColors = Arrays.copyOf(colors, 5);
    innerSeries.setData(new String[] { "MSIE", "Firefox", "Chrome", "Safari", "Opera" }, new Number[] { 55.11, 21.63, 11.94, 7.15, 2.14 }, innerColors);
    DataSeries outerSeries = new DataSeries();
    outerSeries.setName("Versions");
    PlotOptionsPie outerSeriesOptions = new PlotOptionsPie();
    outerSeries.setPlotOptions(outerSeriesOptions);
    outerSeriesOptions.setInnerSize("237px");
    outerSeriesOptions.setSize("318px");
    outerSeriesOptions.setDataLabels(new DataLabels());
    outerSeriesOptions.getDataLabels().setFormatter("this.y > 1 ? '<b>'+ this.point.name +':</b> '+ this.y +'%' : null");
    DataSeriesItem[] outerItems = new DataSeriesItem[] { /* @formatter:off */
    new DataSeriesItem("MSIE 6.0", 10.85, color(0)), new DataSeriesItem("MSIE 7.0", 7.35, color(0)), new DataSeriesItem("MSIE 8.0", 33.06, color(0)), new DataSeriesItem("MSIE 9.0", 2.81, color(0)), new DataSeriesItem("Firefox 2.0", 0.20, color(1)), new DataSeriesItem("Firefox 3.0", 0.83, color(1)), new DataSeriesItem("Firefox 3.5", 1.58, color(1)), new DataSeriesItem("Firefox 3.6", 13.12, color(1)), new DataSeriesItem("Firefox 4.0", 5.43, color(1)), new DataSeriesItem("Chrome 5.0", 0.12, color(2)), new DataSeriesItem("Chrome 6.0", 0.19, color(2)), new DataSeriesItem("Chrome 7.0", 0.12, color(2)), new DataSeriesItem("Chrome 8.0", 0.36, color(2)), new DataSeriesItem("Chrome 9.0", 0.32, color(2)), new DataSeriesItem("Chrome 10.0", 9.91, color(2)), new DataSeriesItem("Chrome 11.0", 0.50, color(2)), new DataSeriesItem("Chrome 12.0", 0.22, color(2)), new DataSeriesItem("Safari 5.0", 4.55, color(3)), new DataSeriesItem("Safari 4.0", 1.42, color(3)), new DataSeriesItem("Safari Win 5.0", 0.23, color(3)), new DataSeriesItem("Safari 4.1", 0.21, color(3)), new DataSeriesItem("Safari/Maxthon", 0.20, color(3)), new DataSeriesItem("Safari 3.1", 0.19, color(3)), new DataSeriesItem("Safari 4.1", 0.14, color(3)), new DataSeriesItem("Opera 9.x", 0.12, color(4)), new DataSeriesItem("Opera 10.x", 0.37, color(4)), new DataSeriesItem("Opera 11.x", 1.65, color(4)) /* @formatter:on */
    };
    outerSeries.setData(Arrays.asList(outerItems));
    conf.setSeries(innerSeries, outerSeries);
    chart.drawChart(conf);
    return chart;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) DataLabels(com.vaadin.addon.charts.model.DataLabels) Random(java.util.Random) Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) 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)

Example 8 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class SVGGeneratorTest method generate_TreemapChart_withoutException.

@Test
public void generate_TreemapChart_withoutException() {
    Chart chart = new Chart(ChartType.TREEMAP);
    Configuration conf = chart.getConfiguration();
    TreeSeries series = new TreeSeries();
    conf.setSeries(series);
    for (int i = 0; i < 10; ++i) {
        double y = Math.random();
        TreeSeriesItem item = new TreeSeriesItem("Attempt " + i, (int) Math.floor(y * 100));
        int r = (int) (255 * y);
        int g = 255 - (int) (255 * y);
        item.setColor(new SolidColor(r, g, 100));
        series.add(item);
    }
    String generatedSVG = SVGGenerator.getInstance().generate(conf);
    Assert.assertTrue(generatedSVG != null);
}
Also used : TreeSeries(com.vaadin.addon.charts.model.TreeSeries) Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) TreeSeriesItem(com.vaadin.addon.charts.model.TreeSeriesItem) Chart(com.vaadin.addon.charts.Chart) Test(org.junit.Test)

Example 9 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class PieWithLegendNavigator method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    Legend legend = conf.getLegend();
    legend.setLayout(VERTICAL);
    legend.setAlign(RIGHT);
    legend.setVerticalAlign(TOP);
    LegendNavigation nav = legend.getNavigation();
    nav.setActiveColor(GREEN);
    nav.setArrowSize(24);
    conf.setTitle("Lot of slices to force navigation in legend");
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.getDataLabels().setEnabled(false);
    plotOptions.setShowInLegend(true);
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries();
    for (int i = 0; i < 50; i++) {
        series.add(new DataSeriesItem("Item " + i, 1));
    }
    conf.addSeries(series);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) Configuration(com.vaadin.addon.charts.model.Configuration) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) LegendNavigation(com.vaadin.addon.charts.model.LegendNavigation) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 10 with Chart

use of com.vaadin.addon.charts.Chart in project charts by vaadin.

the class PieWithStartAndEndAngle method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares at a specific website, 2010");
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setStartAngle(45);
    plotOptions.setEndAngle(180);
    plotOptions.setCursor(Cursor.POINTER);
    DataLabels dataLabels = new DataLabels(true);
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    conf.setPlotOptions(plotOptions);
    conf.setSeries(getBrowserMarketShareSeries());
    chart.drawChart();
    return chart;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Chart(com.vaadin.addon.charts.Chart)

Aggregations

Chart (com.vaadin.addon.charts.Chart)243 Configuration (com.vaadin.addon.charts.model.Configuration)196 YAxis (com.vaadin.addon.charts.model.YAxis)105 DataSeries (com.vaadin.addon.charts.model.DataSeries)81 ListSeries (com.vaadin.addon.charts.model.ListSeries)76 XAxis (com.vaadin.addon.charts.model.XAxis)71 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)57 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)55 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)50 DataLabels (com.vaadin.addon.charts.model.DataLabels)45 Tooltip (com.vaadin.addon.charts.model.Tooltip)44 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)34 Legend (com.vaadin.addon.charts.model.Legend)29 Marker (com.vaadin.addon.charts.model.Marker)23 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)21 Style (com.vaadin.addon.charts.model.style.Style)20 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)19 Labels (com.vaadin.addon.charts.model.Labels)18 VerticalLayout (com.vaadin.ui.VerticalLayout)18 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)16