Search in sources :

Example 16 with Style

use of com.vaadin.addon.charts.model.style.Style in project charts by vaadin.

the class StackedColumn method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Stacked column chart"));
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Apples", "Oranges", "Pears", "Grapes", "Bananas" });
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    yAxis.setTitle(new AxisTitle("Total fruit consumption"));
    StackLabels sLabels = new StackLabels(true);
    yAxis.setStackLabels(sLabels);
    conf.addyAxis(yAxis);
    Legend legend = new Legend();
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-100);
    legend.setY(20);
    conf.setLegend(legend);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("function() { return '<b>'+ this.x +'</b><br/>" + "'+this.series.name +': '+ this.y +'<br/>'+'Total: '+ this.point.stackTotal;}");
    conf.setTooltip(tooltip);
    PlotOptionsColumn plotOptions = new PlotOptionsColumn();
    plotOptions.setStacking(Stacking.NORMAL);
    DataLabels labels = new DataLabels(true);
    Style style = new Style();
    style.setTextShadow("0 0 3px black");
    labels.setStyle(style);
    labels.setColor(new SolidColor("white"));
    plotOptions.setDataLabels(labels);
    conf.setPlotOptions(plotOptions);
    conf.addSeries(new ListSeries("John", new Number[] { 5, 3, 4, 7, 2 }));
    conf.addSeries(new ListSeries("Jane", new Number[] { 2, 2, 3, 2, 1 }));
    conf.addSeries(new ListSeries("Joe", new Number[] { 3, 4, 4, 2, 5 }));
    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) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Title(com.vaadin.addon.charts.model.Title) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) XAxis(com.vaadin.addon.charts.model.XAxis) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.addon.charts.model.ListSeries) StackLabels(com.vaadin.addon.charts.model.StackLabels) Style(com.vaadin.addon.charts.model.style.Style) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 17 with Style

use of com.vaadin.addon.charts.model.style.Style 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 18 with Style

use of com.vaadin.addon.charts.model.style.Style in project charts by vaadin.

the class PieWithNativeDrilldown method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market share, April, 2011");
    conf.setSubTitle("Click the columns to view versions. Click again to view brands.");
    conf.getLegend().setEnabled(false);
    PlotOptionsPie column = new PlotOptionsPie();
    column.setCursor(Cursor.POINTER);
    column.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(column);
    Tooltip tooltip = new Tooltip();
    tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
    tooltip.setPointFormat("<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
    conf.setTooltip(tooltip);
    DataSeries series = new DataSeries();
    series.setName("Browser brands");
    DataSeriesItem item = new DataSeriesItem("MSIE", 55.11);
    DataSeries drillSeries = new DataSeries("MSIE versions");
    drillSeries.setId("MSIE");
    String[] categories = new String[] { "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0" };
    Number[] ys = new Number[] { 10.85, 7.35, 33.06, 2.81 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Firefox", 21.63);
    drillSeries = new DataSeries("Firefox versions");
    drillSeries.setId("Firefox");
    categories = new String[] { "Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0" };
    ys = new Number[] { 0.20, 0.83, 1.58, 13.12, 5.43 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Chrome", 11.94);
    drillSeries = new DataSeries("Chrome versions");
    drillSeries.setId("Chrome");
    categories = new String[] { "Chrome 5.0", "Chrome 6.0", "Chrome 7.0", "Chrome 8.0", "Chrome 9.0", "Chrome 10.0", "Chrome 11.0", "Chrome 12.0" };
    ys = new Number[] { 0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    item = new DataSeriesItem("Safari", 7.15);
    series.add(item);
    item = new DataSeriesItem("Opera", 2.14);
    drillSeries = new DataSeries("Opera versions");
    drillSeries.setId("Opera");
    categories = new String[] { "Opera 9.x", "Opera 10.x", "Opera 11.x" };
    ys = new Number[] { 0.12, 0.37, 1.65 };
    drillSeries.setData(categories, ys);
    series.addItemWithDrilldown(item, drillSeries);
    conf.addSeries(series);
    Drilldown drilldown = conf.getDrilldown();
    Style style = new Style();
    style.setFontWeight(BOLD);
    style.setColor(FIREBRICK);
    style.setFontSize("16px");
    drilldown.setActiveDataLabelStyle(style);
    DrillUpButton button = drilldown.getDrillUpButton();
    button.setRelativeTo(SPACINGBOX);
    DrillUpButtonTheme theme = new DrillUpButtonTheme();
    GradientColor gradient1 = GradientColor.createLinear(0, 0, 0, 1);
    gradient1.addColorStop(0, ALICEBLUE);
    gradient1.addColorStop(1, ANTIQUEWHITE);
    theme.setFill(gradient1);
    button.setTheme(theme);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) Tooltip(com.vaadin.addon.charts.model.Tooltip) PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) Drilldown(com.vaadin.addon.charts.model.Drilldown) Style(com.vaadin.addon.charts.model.style.Style) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) DrillUpButton(com.vaadin.addon.charts.model.DrillUpButton) DrillUpButtonTheme(com.vaadin.addon.charts.model.DrillUpButtonTheme)

Example 19 with Style

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

Example 20 with Style

use of com.vaadin.addon.charts.model.style.Style in project charts by vaadin.

the class SplineWithItemLabels method getDataLabels.

private DataLabels getDataLabels() {
    DataLabels dataLabels = new DataLabels(true);
    dataLabels.setStyle(new Style());
    dataLabels.getStyle().setFontWeight(BOLD);
    dataLabels.setY(-20);
    dataLabels.setShape(CIRCLE);
    dataLabels.setBackgroundColor(SolidColor.BLUEVIOLET);
    dataLabels.setColor(SolidColor.WHITESMOKE);
    dataLabels.setVerticalAlign(MIDDLE);
    return dataLabels;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Style(com.vaadin.addon.charts.model.style.Style)

Aggregations

Style (com.vaadin.addon.charts.model.style.Style)25 Chart (com.vaadin.addon.charts.Chart)20 Configuration (com.vaadin.addon.charts.model.Configuration)16 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)15 YAxis (com.vaadin.addon.charts.model.YAxis)13 DataLabels (com.vaadin.addon.charts.model.DataLabels)11 DataSeries (com.vaadin.addon.charts.model.DataSeries)10 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)9 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)9 XAxis (com.vaadin.addon.charts.model.XAxis)9 Legend (com.vaadin.addon.charts.model.Legend)7 Tooltip (com.vaadin.addon.charts.model.Tooltip)7 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)6 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)6 Labels (com.vaadin.addon.charts.model.Labels)5 ListSeries (com.vaadin.addon.charts.model.ListSeries)5 Title (com.vaadin.addon.charts.model.Title)4 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)4 DashStyle (com.vaadin.addon.charts.model.DashStyle)3 Label (com.vaadin.addon.charts.model.Label)3