Search in sources :

Example 16 with Labels

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

the class MultipleAxes method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    Color[] colors = getThemeColors();
    conf.getChart().setZoomType(ZoomType.XY);
    conf.setTitle("Average Monthly Weather Data for 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 y1 = new YAxis();
    Labels labels = new Labels();
    labels.setFormatter("return this.value +'°C'");
    Style style = new Style();
    style.setColor(colors[1]);
    labels.setStyle(style);
    y1.setLabels(labels);
    y1.setOpposite(true);
    AxisTitle title = new AxisTitle("Temperature");
    style = new Style();
    style.setColor(colors[1]);
    y1.setTitle(title);
    conf.addyAxis(y1);
    YAxis y2 = new YAxis();
    y2.setGridLineWidth(0);
    title = new AxisTitle("Rainfall");
    style = new Style();
    style.setColor(colors[0]);
    y2.setTitle(title);
    labels = new Labels();
    labels.setFormatter("this.value +' mm'");
    style = new Style();
    style.setColor(colors[0]);
    labels.setStyle(style);
    y2.setLabels(labels);
    conf.addyAxis(y2);
    YAxis y3 = new YAxis();
    y3.setGridLineWidth(0);
    conf.addyAxis(y3);
    title = new AxisTitle("Sea-Level Pressure");
    style = new Style();
    style.setColor(colors[2]);
    y3.setTitle(title);
    labels = new Labels();
    labels.setFormatter("this.value +' mb'");
    style = new Style();
    style.setColor(colors[2]);
    labels.setStyle(style);
    y3.setLabels(labels);
    y3.setOpposite(true);
    chart.drawChart(conf);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("function() { " + "var unit = { 'Rainfall': 'mm', 'Temperature': '°C', 'Sea-Level Pressure': 'mb' }[this.series.name];" + "return ''+ this.x +': '+ this.y +' '+ unit; }");
    conf.setTooltip(tooltip);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setX(120);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setY(80);
    legend.setFloating(true);
    conf.setLegend(legend);
    DataSeries series = new DataSeries();
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColor(colors[0]);
    series.setPlotOptions(plotOptionsColumn);
    series.setName("Rainfall");
    series.setyAxis(1);
    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);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
    plotOptionsSpline.setColor(colors[2]);
    series.setPlotOptions(plotOptionsSpline);
    series.setName("Sea-Level Pressure");
    series.setyAxis(2);
    series.setData(1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptionsSpline = new PlotOptionsSpline();
    plotOptionsSpline.setColor(colors[1]);
    series.setPlotOptions(plotOptionsSpline);
    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.drawChart(conf);
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) Color(com.vaadin.addon.charts.model.style.Color) Tooltip(com.vaadin.addon.charts.model.Tooltip) Labels(com.vaadin.addon.charts.model.Labels) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) XAxis(com.vaadin.addon.charts.model.XAxis) 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) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 17 with Labels

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

the class VUMeter method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("600px");
    chart.setHeight("200px");
    GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1);
    gradient.addColorStop(0, new SolidColor("#FFF4C6"));
    gradient.addColorStop(0.3, new SolidColor("#FFFFFF"));
    gradient.addColorStop(1, new SolidColor("#FFF4C6"));
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.getChart().setPlotBackgroundColor(gradient);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(1);
    configuration.setTitle("VU meter");
    Pane pane1 = new Pane(-45, 45);
    Pane pane2 = new Pane(-45, 45);
    pane1.setBackground(new Background[] {});
    pane2.setBackground(new Background[] {});
    pane1.setCenter("25%", "145%");
    pane2.setCenter("75%", "145%");
    pane1.setSize("300px");
    pane2.setSize("300");
    configuration.addPane(pane1);
    configuration.addPane(pane2);
    PlotBand plotBand1 = new PlotBand(0, 6, new SolidColor("#C02316"));
    plotBand1.setInnerRadius("100%");
    plotBand1.setOuterRadius("105%");
    PlotBand plotBand2 = new PlotBand(0, 6, new SolidColor("#C02316"));
    plotBand2.setInnerRadius("100%");
    plotBand2.setOuterRadius("105%");
    YAxis yAxis = new YAxis();
    yAxis.setPane(pane1);
    yAxis.setTitle("VU<br/><span style=\"font-size:8px\">Channel A</span>");
    yAxis.getTitle().setY(-40);
    yAxis.setMin(-20);
    yAxis.setMax(6);
    yAxis.setTickPosition(TickPosition.OUTSIDE);
    yAxis.setMinorTickPosition(TickPosition.OUTSIDE);
    Labels labels = new Labels();
    labels.setDistance(20);
    labels.setRotationPerpendicular();
    yAxis.setLabels(labels);
    yAxis.setPlotBands(plotBand1);
    YAxis yAxis2 = new YAxis();
    yAxis2.setPane(pane2);
    yAxis2.setTitle("VU<br/><span style=\"font-size:8px\">Channel B</span>");
    yAxis2.getTitle().setY(-40);
    yAxis2.setMin(-20);
    yAxis2.setMax(6);
    yAxis2.setTickPosition(TickPosition.OUTSIDE);
    yAxis2.setMinorTickPosition(TickPosition.OUTSIDE);
    labels = new Labels();
    labels.setDistance(20);
    labels.setRotationPerpendicular();
    yAxis2.setLabels(labels);
    yAxis2.setPlotBands(plotBand2);
    configuration.addyAxis(yAxis);
    configuration.addyAxis(yAxis2);
    PlotOptionsGauge gauge = new PlotOptionsGauge();
    gauge.setDataLabels(new DataLabels(false));
    gauge.setDial(new Dial());
    gauge.getDial().setRadius("100%");
    configuration.setPlotOptions(gauge);
    final ListSeries series1 = new ListSeries(-20);
    final ListSeries series2 = new ListSeries(-20);
    series1.setyAxis(0);
    series2.setyAxis(1);
    configuration.setSeries(series1, series2);
    runWhileAttached(chart, new Runnable() {

        final Random r = new Random(0);

        @Override
        public void run() {
            double left = series1.getData()[0].doubleValue();
            double inc = (r.nextDouble() - 0.5) * 3;
            double leftVal = left + inc;
            double rightVal = leftVal + inc / 3;
            if (leftVal < -20 || leftVal > 6) {
                leftVal = left - inc;
            }
            if (rightVal < -20 || rightVal > 6) {
                rightVal = leftVal;
            }
            series1.updatePoint(0, leftVal);
            series2.updatePoint(0, rightVal);
        }
    }, 500, 12000);
    chart.drawChart(configuration);
    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) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Pane(com.vaadin.addon.charts.model.Pane) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Dial(com.vaadin.addon.charts.model.Dial) Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 18 with Labels

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

the class ColumnWithRotatedLabels method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setMargin(50, 80, 100, 50);
    conf.setTitle(new Title("World's largest cities per 2008"));
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Tokyo", "Jakarta", "New York", "Seoul", "Manila", "Mumbai", "Sao Paulo", "Mexico City", "Dehli", "Osaka", "Cairo", "Kolkata", "Los Angeles", "Shanghai", "Moscow", "Beijing", "Buenos Aires", "Guangzhou", "Shenzhen", "Istanbul");
    Labels labels = new Labels();
    labels.setRotation(-45);
    labels.setAlign(HorizontalAlign.RIGHT);
    Style style = new Style();
    style.setFontSize("13px");
    style.setFontFamily("Verdana, sans-serif");
    labels.setStyle(style);
    xAxis.setLabels(labels);
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    yAxis.setTitle(new AxisTitle("Population (millions)"));
    conf.addyAxis(yAxis);
    Legend legend = new Legend();
    legend.setEnabled(false);
    conf.setLegend(legend);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("'<b>'+ this.x +'</b><br/>'+'Population in 2008: '" + "+ Highcharts.numberFormat(this.y, 1) +' millions'");
    conf.setTooltip(tooltip);
    ListSeries serie = new ListSeries("Population", new Number[] { 34.4, 21.8, 20.1, 20, 19.6, 19.5, 19.1, 18.4, 18, 17.3, 16.8, 15, 14.7, 14.5, 13.3, 12.8, 12.4, 11.8, 11.7, 11.2 });
    DataLabels dataLabels = new DataLabels();
    dataLabels.setEnabled(true);
    dataLabels.setRotation(-90);
    dataLabels.setColor(new SolidColor(255, 255, 255));
    dataLabels.setAlign(HorizontalAlign.RIGHT);
    dataLabels.setX(4);
    dataLabels.setY(10);
    dataLabels.setFormatter("this.y");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setDataLabels(dataLabels);
    serie.setPlotOptions(plotOptionsColumn);
    conf.addSeries(serie);
    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) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) XAxis(com.vaadin.addon.charts.model.XAxis) ListSeries(com.vaadin.addon.charts.model.ListSeries) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) 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 19 with Labels

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

the class LabelsJSONSerializationTest method toJSON_paddingIsSet_labelsSerializedWithPadding.

@Test
public void toJSON_paddingIsSet_labelsSerializedWithPadding() throws IOException {
    Labels labels = new Labels(true);
    labels.setPadding(8);
    ObjectMapper om = ChartSerialization.createObjectMapper();
    String json = toJSON(labels);
    Labels fromJson = om.readValue(json, Labels.class);
    assertEquals(8, fromJson.getPadding());
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 20 with Labels

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

the class ChartConfiguration method labelsSnippet2.

public void labelsSnippet2(XAxis xaxis) {
    Labels xlabels = xaxis.getLabels();
    xlabels.setAlign(HorizontalAlign.RIGHT);
    // Tilt 45 degrees CCW
    xlabels.setRotation(-45);
}
Also used : Labels(com.vaadin.addon.charts.model.Labels)

Aggregations

Labels (com.vaadin.addon.charts.model.Labels)29 Configuration (com.vaadin.addon.charts.model.Configuration)19 YAxis (com.vaadin.addon.charts.model.YAxis)19 Chart (com.vaadin.addon.charts.Chart)18 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)12 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)12 ListSeries (com.vaadin.addon.charts.model.ListSeries)11 DataLabels (com.vaadin.addon.charts.model.DataLabels)9 XAxis (com.vaadin.addon.charts.model.XAxis)9 DataSeries (com.vaadin.addon.charts.model.DataSeries)8 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 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)4 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