Search in sources :

Example 26 with Legend

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

the class BarWithLegendLabelFormatter method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.BAR);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Historic World Population by Region");
    conf.setSubTitle("Source: Wikipedia.org");
    Legend legend = new Legend();
    legend.setLabelFormatter("function() { return this.name + ' (click to hide)'; }");
    conf.setLegend(legend);
    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 chart;
}
Also used : ListSeries(com.vaadin.addon.charts.model.ListSeries) Series(com.vaadin.addon.charts.model.Series) Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) ArrayList(java.util.ArrayList) Chart(com.vaadin.addon.charts.Chart)

Example 27 with Legend

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

the class VaadinThemedBasicLine method getChart.

@Override
protected Component getChart() {
    // Vaadin theme is on by default
    // ChartTheme.get().setTheme(new VaadinTheme());
    // disable some customizations from super
    Chart chart = (Chart) super.getChart();
    Legend legend = chart.getConfiguration().getLegend();
    Style itemHoverStyle = new Style();
    legend.setItemHoverStyle(itemHoverStyle);
    legend.setBorderWidth(null);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Style(com.vaadin.addon.charts.model.style.Style) Chart(com.vaadin.addon.charts.Chart)

Example 28 with Legend

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

the class PointClickCoordinatesColumnChart method createChart.

@Override
protected Chart createChart() {
    Chart chart = super.createChart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Total fruit consumption, grouped by gender");
    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);
    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) 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 29 with Legend

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

the class SVGGeneratorTest method testWide.

@Test
public void testWide() throws InterruptedException, URISyntaxException {
    Configuration conf = new Configuration();
    conf.getChart().setType(ChartType.COLUMN);
    conf.getChart().setMarginRight(200);
    Legend legend = conf.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.MIDDLE);
    legend.setBorderWidth(0);
    Random r = new Random();
    for (int i = 0; i < 20; i++) {
        String name = RandomStringUtils.randomAlphabetic(r.nextInt(20));
        DataSeries dataSeries = new DataSeries(name);
        dataSeries.add(new DataSeriesItem(name, r.nextInt(100)));
        conf.addSeries(dataSeries);
    }
    SVGGenerator instance = SVGGenerator.getInstance();
    String generatedSVG = instance.withHeight(400).withWidth(1200).generate(conf);
    Assert.assertTrue(generatedSVG.contains("width=\"1200\""));
    Assert.assertTrue(generatedSVG.contains("height=\"400\""));
    SVGGenerator.getInstance().destroy();
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) Random(java.util.Random) SVGGenerator(com.vaadin.addon.charts.util.SVGGenerator) DataSeries(com.vaadin.addon.charts.model.DataSeries) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) Test(org.junit.Test)

Example 30 with Legend

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

the class BasicLineGettingMousePointerPosition method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setId("chart");
    Color[] colors = getThemeColors();
    Configuration conf = chart.getConfiguration();
    conf.getChart().setZoomType(ZoomType.XY);
    conf.setTitle("Average Monthly Temperature and Rainfall in Tokyo");
    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 primary = new YAxis();
    primary.setTitle("Temperature");
    Style style = new Style();
    style.setColor(colors[0]);
    primary.getTitle().setStyle(style);
    conf.addyAxis(primary);
    YAxis snd = new YAxis();
    snd.setTitle("Rainfall");
    snd.setOpposite(true);
    style = new Style();
    style.setColor(colors[1]);
    snd.getTitle().setStyle(style);
    conf.addyAxis(snd);
    Tooltip tooltip = new Tooltip(false);
    conf.setTooltip(tooltip);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setX(120);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setY(100);
    legend.setFloating(true);
    legend.setBackgroundColor(new SolidColor("#FFFFFF"));
    conf.setLegend(legend);
    DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsColumn());
    series.setName("Rainfall");
    series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    series.setyAxis(1);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    series.setPlotOptions(plotOptions);
    series.setName("Temperature");
    series.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);
    conf.addSeries(series);
    chart.addPointClickListener(new PointClickListener() {

        @Override
        public void onClick(PointClickEvent event) {
            Window win = new Window("PointClickEvent window");
            win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
            win.setPositionX(event.getAbsoluteX());
            win.setPositionY(event.getAbsoluteY());
            getUI().addWindow(win);
        }
    });
    chart.addChartClickListener(new ChartClickListener() {

        @Override
        public void onClick(ChartClickEvent event) {
            Window win = new Window("Chart Click Event Window");
            win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
            win.setPositionX(event.getAbsoluteX());
            win.setPositionY(event.getAbsoluteY());
            getUI().addWindow(win);
        }
    });
    return chart;
}
Also used : Window(com.vaadin.ui.Window) Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) Tooltip(com.vaadin.addon.charts.model.Tooltip) PointClickEvent(com.vaadin.addon.charts.PointClickEvent) Label(com.vaadin.ui.Label) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) ChartClickEvent(com.vaadin.addon.charts.ChartClickEvent) ChartClickListener(com.vaadin.addon.charts.ChartClickListener) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) PointClickListener(com.vaadin.addon.charts.PointClickListener) Style(com.vaadin.addon.charts.model.style.Style) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Legend (com.vaadin.addon.charts.model.Legend)35 Configuration (com.vaadin.addon.charts.model.Configuration)30 Chart (com.vaadin.addon.charts.Chart)29 YAxis (com.vaadin.addon.charts.model.YAxis)24 XAxis (com.vaadin.addon.charts.model.XAxis)20 ListSeries (com.vaadin.addon.charts.model.ListSeries)19 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)17 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)15 Tooltip (com.vaadin.addon.charts.model.Tooltip)14 DataSeries (com.vaadin.addon.charts.model.DataSeries)10 DataLabels (com.vaadin.addon.charts.model.DataLabels)9 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)8 Style (com.vaadin.addon.charts.model.style.Style)7 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)6 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)5 Series (com.vaadin.addon.charts.model.Series)5 Title (com.vaadin.addon.charts.model.Title)5 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)4 ArrayList (java.util.ArrayList)4 Labels (com.vaadin.addon.charts.model.Labels)3