Search in sources :

Example 1 with Labels

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

the class Sparkline method configureXAxis.

protected void configureXAxis(XAxis axis) {
    axis.setLineWidth(0);
    axis.setMinorGridLineWidth(0);
    axis.setMinorTickLength(0);
    axis.setMinorTickWidth(0);
    axis.setGridLineWidth(0);
    axis.setMaxPadding(0.1);
    axis.setMinPadding(0.1);
    axis.setLabels(new Labels(false));
    axis.setLineColor(new SolidColor(0, 0, 0, 0));
    axis.setTitle("");
    axis.setStartOnTick(false);
    axis.setEndOnTick(false);
}
Also used : SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels)

Example 2 with Labels

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

the class CompareMultipleSeries method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("(this.value > 0 ? ' + ' : '') + this.value + '%'");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span style=\"color:{series.color}\">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>");
    tooltip.setValueDecimals(2);
    configuration.setTooltip(tooltip);
    DataSeries aaplSeries = new DataSeries();
    aaplSeries.setName("AAPL");
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    DataSeries googSeries = new DataSeries();
    googSeries.setName("GOOG");
    for (StockPrices.PriceData data : StockPrices.fetchGoogPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        googSeries.add(item);
    }
    DataSeries msftSeries = new DataSeries();
    msftSeries.setName("MSFT");
    for (StockPrices.PriceData data : StockPrices.fetchMsftPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        msftSeries.add(item);
    }
    configuration.setSeries(aaplSeries, googSeries, msftSeries);
    PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
    plotOptionsSeries.setCompare(PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    chart.drawChart(configuration);
    return chart;
}
Also used : StockPrices(com.vaadin.addon.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.addon.charts.model.Configuration) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) Tooltip(com.vaadin.addon.charts.model.Tooltip) Labels(com.vaadin.addon.charts.model.Labels) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 3 with Labels

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

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

the class ErrorBarExample method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    Color[] colors = getThemeColors();
    // Enable xy zooming, test also with touch devices
    conf.getChart().setZoomType(ZoomType.XY);
    conf.setTitle("Temperature vs Rainfall");
    conf.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis primaryAxis = conf.getyAxis();
    AxisTitle title = new AxisTitle("Temperature");
    Style style = new Style();
    style.setColor(colors[0]);
    title.setStyle(style);
    primaryAxis.setTitle(title);
    Labels labels = new Labels();
    labels.setFormatter("this.value + '°C'");
    primaryAxis.setLabels(labels);
    YAxis secondaryAxis = new YAxis();
    conf.addyAxis(secondaryAxis);
    title = new AxisTitle("Rainfall");
    secondaryAxis.setTitle(title);
    style = new Style();
    style.setColor(colors[1]);
    title.setStyle(style);
    labels = new Labels();
    labels.setFormatter("this.value + ' mm'");
    labels.setStyle(style);
    secondaryAxis.setLabels(labels);
    secondaryAxis.setOpposite(true);
    conf.getTooltip().setShared(true);
    DataSeries rainfall = new DataSeries("Rainfall");
    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setColor(colors[1]);
    SeriesTooltip tooltip = new SeriesTooltip();
    tooltip.setPointFormat("<span style='font-weight: bold; color: {series.color}'>{series.name}</span>: <b>{point.y:.1f} mm</b> ");
    column.setTooltip(tooltip);
    rainfall.setPlotOptions(column);
    conf.addSeries(rainfall);
    rainfall.setyAxis(secondaryAxis);
    DataSeries rainfallError = new DataSeries("Rainfall");
    conf.addSeries(rainfallError);
    rainfallError.setyAxis(secondaryAxis);
    PlotOptionsErrorbar rainErrorOptions = new PlotOptionsErrorbar();
    tooltip = new SeriesTooltip();
    tooltip.setPointFormat("(error range: {point.low}-{point.high} mm)<br/>");
    rainErrorOptions.setTooltip(tooltip);
    rainfallError.setPlotOptions(rainErrorOptions);
    DataSeries temperature = new DataSeries("Temperature");
    conf.addSeries(temperature);
    PlotOptionsSpline tempOptions = new PlotOptionsSpline();
    tempOptions.setColor(colors[0]);
    tooltip = new SeriesTooltip();
    tooltip.setPointFormat("<span style='font-weight: bold; color: {series.color}'>{series.name}</span>: <b>{point.y:.1f}°C");
    tempOptions.setTooltip(tooltip);
    temperature.setPlotOptions(tempOptions);
    DataSeries temperatureErrors = new DataSeries("Temperature error");
    conf.addSeries(temperatureErrors);
    PlotOptionsErrorbar tempErrorOptions = new PlotOptionsErrorbar();
    SolidColor green = new SolidColor("green");
    tempErrorOptions.setStemColor(green);
    tempErrorOptions.setWhiskerColor(green);
    tooltip = new SeriesTooltip();
    tooltip.setPointFormat("(error range: {point.low}-{point.high}°C)<br/>");
    tempErrorOptions.setTooltip(tooltip);
    temperatureErrors.setPlotOptions(tempErrorOptions);
    // Populate series
    for (Data d : DATA) {
        DataSeriesItem item = new DataSeriesItem();
        item.setY(d.rainfall);
        rainfall.add(item);
        item = new DataSeriesItem();
        item.setLow(d.rainfallErrorLow);
        item.setHigh(d.rainfallErrorHigh);
        rainfallError.add(item);
        item = new DataSeriesItem();
        item.setY(d.temperature);
        temperature.add(item);
        item = new DataSeriesItem();
        item.setLow(d.temperatureErrorLow);
        item.setHigh(d.temperatureErrorHigh);
        temperatureErrors.add(item);
    }
    return chart;
}
Also used : PlotOptionsErrorbar(com.vaadin.addon.charts.model.PlotOptionsErrorbar) 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) Labels(com.vaadin.addon.charts.model.Labels) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) Style(com.vaadin.addon.charts.model.style.Style) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

Example 5 with Labels

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

the class SplineWithSymbols method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Temperature"));
    Labels labels = new Labels();
    labels.setFormatter("this.value +'°'");
    yAxis.setLabels(labels);
    configuration.getTooltip().setShared(true);
    configuration.getxAxis().setCrosshair(new Crosshair());
    PlotOptionsSpline plotOptions = new PlotOptionsSpline();
    configuration.setPlotOptions(plotOptions);
    plotOptions.setMarker(new Marker(true));
    plotOptions.getMarker().setRadius(4);
    plotOptions.getMarker().setLineColor(new SolidColor("#666666"));
    plotOptions.getMarker().setLineWidth(1);
    DataSeries ls = new DataSeries();
    plotOptions = new PlotOptionsSpline();
    Marker marker = new Marker();
    marker.setSymbol(MarkerSymbolEnum.SQUARE);
    plotOptions.setMarker(marker);
    ls.setPlotOptions(plotOptions);
    ls.setName("Tokyo");
    ls.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);
    ls.get("26.5").getMarker().setSymbol(new MarkerSymbolUrl("http://www.highcharts.com/demo/gfx/sun.png"));
    configuration.addSeries(ls);
    ls = new DataSeries();
    plotOptions = new PlotOptionsSpline();
    marker = new Marker();
    marker.setSymbol(MarkerSymbolEnum.DIAMOND);
    plotOptions.setMarker(marker);
    ls.setPlotOptions(plotOptions);
    ls.setName("London");
    ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
    ls.get("3.9").getMarker().setSymbol(new MarkerSymbolUrl("http://www.highcharts.com/demo/gfx/snow.png"));
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : MarkerSymbolUrl(com.vaadin.addon.charts.model.MarkerSymbolUrl) Configuration(com.vaadin.addon.charts.model.Configuration) Crosshair(com.vaadin.addon.charts.model.Crosshair) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) DataSeries(com.vaadin.addon.charts.model.DataSeries) Marker(com.vaadin.addon.charts.model.Marker) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Labels (com.vaadin.addon.charts.model.Labels)28 YAxis (com.vaadin.addon.charts.model.YAxis)19 Chart (com.vaadin.addon.charts.Chart)18 Configuration (com.vaadin.addon.charts.model.Configuration)18 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 ListSeries (com.vaadin.addon.charts.model.ListSeries)11 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)11 DataLabels (com.vaadin.addon.charts.model.DataLabels)9 XAxis (com.vaadin.addon.charts.model.XAxis)9 DataSeries (com.vaadin.addon.charts.model.DataSeries)7 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)5 Tooltip (com.vaadin.addon.charts.model.Tooltip)5 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)5 Style (com.vaadin.addon.charts.model.style.Style)5 Marker (com.vaadin.addon.charts.model.Marker)4 Pane (com.vaadin.addon.charts.model.Pane)4 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)4 PlotOptionsGauge (com.vaadin.addon.charts.model.PlotOptionsGauge)4 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)4 SeriesTooltip (com.vaadin.addon.charts.model.SeriesTooltip)4