Search in sources :

Example 1 with DataLabels

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

the class SVGGeneratorTest method createConf.

private Configuration createConf() {
    Configuration conf = new Configuration();
    conf.setTitle("Historic World Population by Region");
    conf.setSubTitle("Source: Wikipedia.org");
    XAxis x = new XAxis();
    x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
    x.setTitle(new AxisTitle((String) null));
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    AxisTitle title = new AxisTitle("Population (millions)");
    title.setAlign(VerticalAlign.HIGH);
    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);
    return conf;
}
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) TreeSeries(com.vaadin.addon.charts.model.TreeSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with DataLabels

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

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

Example 4 with DataLabels

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

the class Basic3DPie method createChart.

public static Chart createChart() {
    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.setCursor(Cursor.POINTER);
    DataLabels dataLabels = new DataLabels(true);
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    plotOptions.setDepth(45);
    conf.setPlotOptions(plotOptions);
    final DataSeries series = new DataSeries();
    series.add(new DataSeriesItem("Firefox", 45.0));
    series.add(new DataSeriesItem("IE", 26.8));
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Safari", 8.5));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("Others", 0.7));
    conf.setSeries(series);
    Options3d options3d = new Options3d();
    options3d.setEnabled(true);
    options3d.setAlpha(60);
    conf.getChart().setOptions3d(options3d);
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            Notification.show("Click: " + series.get(event.getPointIndex()).getName());
        }
    });
    chart.drawChart(conf);
    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) PointClickListener(com.vaadin.addon.charts.PointClickListener) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Options3d(com.vaadin.addon.charts.model.Options3d)

Example 5 with DataLabels

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

the class PieChart method createChart.

public static Chart createChart() {
    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.setCursor(Cursor.POINTER);
    DataLabels dataLabels = new DataLabels();
    dataLabels.setEnabled(true);
    dataLabels.setFormatter("'<b>'+ this.point.name +'</b>: '+ this.percentage +' %'");
    plotOptions.setDataLabels(dataLabels);
    conf.setPlotOptions(plotOptions);
    final DataSeries series = new DataSeries();
    series.add(new DataSeriesItem("Firefox", 45.0));
    series.add(new DataSeriesItem("IE", 26.8));
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Safari", 8.5));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("Others", 0.7));
    conf.setSeries(series);
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            Notification.show("Click: " + series.get(event.getPointIndex()).getName());
        }
    });
    chart.drawChart(conf);
    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) PointClickListener(com.vaadin.addon.charts.PointClickListener) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Aggregations

DataLabels (com.vaadin.addon.charts.model.DataLabels)53 Chart (com.vaadin.addon.charts.Chart)46 Configuration (com.vaadin.addon.charts.model.Configuration)43 YAxis (com.vaadin.addon.charts.model.YAxis)31 DataSeries (com.vaadin.addon.charts.model.DataSeries)24 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)20 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)19 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)18 ListSeries (com.vaadin.addon.charts.model.ListSeries)17 XAxis (com.vaadin.addon.charts.model.XAxis)17 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)13 Tooltip (com.vaadin.addon.charts.model.Tooltip)13 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)12 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