Search in sources :

Example 26 with Labels

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

the class PolarChart method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.getChart().setPolar(true);
    conf.setTitle("Polar Chart");
    Pane pane = new Pane(0, 360);
    conf.addPane(pane);
    pane.setBackground(new Background[] {});
    XAxis axis = new XAxis();
    axis.setTickInterval(45);
    axis.setMin(0);
    axis.setMax(360);
    Labels labels = new Labels();
    labels.setFormatter("function() {return this.value + '°';}");
    axis.setLabels(labels);
    YAxis yaxs = new YAxis();
    yaxs.setMin(0);
    conf.addxAxis(axis);
    conf.addyAxis(yaxs);
    PlotOptionsSeries series = new PlotOptionsSeries();
    PlotOptionsColumn column = new PlotOptionsColumn();
    series.setPointStart(0);
    series.setPointInterval(45);
    column.setPointPadding(0);
    column.setGroupPadding(0);
    conf.setPlotOptions(series, column);
    ListSeries col = new ListSeries(8, 7, 6, 5, 4, 3, 2, 1);
    ListSeries line = new ListSeries(1, 2, 3, 4, 5, 6, 7, 8);
    ListSeries area = new ListSeries(1, 8, 2, 7, 3, 6, 4, 5);
    col.setPlotOptions(new PlotOptionsColumn());
    col.setName(ChartType.COLUMN.toString());
    line.setPlotOptions(new PlotOptionsLine());
    line.setName(ChartType.LINE.toString());
    area.setPlotOptions(new PlotOptionsArea());
    area.setName(ChartType.AREA.toString());
    conf.setSeries(col, line, area);
    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) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) Labels(com.vaadin.addon.charts.model.Labels) Pane(com.vaadin.addon.charts.model.Pane) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 27 with Labels

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

the class BasicLineWithCallouts method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.LINE);
    configuration.getTitle().setText("CALLOUT: 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 (°C)"));
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    Labels dataLabels = new Labels(false);
    plotOptions.setEnableMouseTracking(false);
    configuration.setPlotOptions(plotOptions);
    DataSeries ds = new DataSeries();
    ds.setName("Tokyo");
    ds.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);
    DataLabels callout = new DataLabels(true);
    callout.setShape(Shape.CALLOUT);
    callout.setBackgroundColor(SolidColor.BLANCHEDALMOND);
    callout.setY(-12);
    ds.get(5).setDataLabels(callout);
    configuration.addSeries(ds);
    ds = new DataSeries();
    ds.setName("London");
    ds.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);
    ds.get(7).setDataLabels(callout);
    configuration.addSeries(ds);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) 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 28 with Labels

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

the class Clock method getChart.

@Override
protected Chart getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");
    chart.setHeight("200px");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.getChart().setPlotBackgroundColor(null);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(0);
    configuration.getChart().setPlotShadow(false);
    configuration.setTitle("The Vaadin Charts clock");
    configuration.getCredits().setEnabled(false);
    GradientColor gradient1 = GradientColor.createRadial(0.5, -0.4, 1.9);
    gradient1.addColorStop(0.5, new SolidColor(255, 255, 255, 0.2));
    gradient1.addColorStop(0.5, new SolidColor(200, 200, 200, 0.2));
    Background[] background = new Background[2];
    background[0] = new Background();
    background[1] = new Background();
    background[1].setBackgroundColor(gradient1);
    background[1].setBorderWidth(1);
    background[1].setOuterRadius("107%");
    configuration.getPane().setBackground(background);
    YAxis yAxis = configuration.getyAxis();
    Labels labels = new Labels();
    labels.setDistance(-20);
    yAxis.setLabels(labels);
    yAxis.setMin(0);
    yAxis.setMax(12);
    yAxis.setLineWidth(0);
    yAxis.setShowFirstLabel(false);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickWidth(1);
    yAxis.setMinorTickLength(5);
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    yAxis.setMinorGridLineWidth(0);
    yAxis.setMinorTickColor(new SolidColor("#666"));
    yAxis.setTickInterval(1);
    yAxis.setTickWidth(2);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setTickLength(10);
    yAxis.setTickColor(new SolidColor("#666"));
    yAxis.setTitle(new AxisTitle("Powered by<br/>Vaadin Charts"));
    yAxis.getTitle().setStyle(new Style());
    yAxis.getTitle().getStyle().setColor(new SolidColor("#BBB"));
    yAxis.getTitle().getStyle().setFontWeight(FontWeight.BOLD);
    yAxis.getTitle().getStyle().setFontSize("8px");
    yAxis.getTitle().getStyle().setLineHeight("10px");
    yAxis.getTitle().setY(10);
    final DataSeries series = new DataSeries();
    final DataSeriesItem hour = new DataSeriesItem();
    final DataSeriesItem minute = new DataSeriesItem();
    final DataSeriesItem second = new DataSeriesItem();
    hour.setId("hour");
    hour.setY(10);
    hour.setDial(new Dial());
    hour.getDial().setRadius("60%");
    hour.getDial().setBaseWidth(4);
    hour.getDial().setRearLength("0%");
    hour.getDial().setBaseLength("95%");
    minute.setId("minute");
    minute.setY(10);
    minute.setDial(new Dial());
    minute.getDial().setBaseLength("95%");
    minute.getDial().setRearLength("0%");
    second.setId("second");
    second.setY(30);
    second.setDial(new Dial());
    second.getDial().setRadius("100%");
    second.getDial().setBaseWidth(1);
    second.getDial().setRearLength("20%");
    series.add(hour);
    series.add(minute);
    series.add(second);
    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    plotOptionsGauge.setDataLabels(new DataLabels(false));
    configuration.setPlotOptions(plotOptionsGauge);
    configuration.setSeries(series);
    final Calendar cal = Calendar.getInstance();
    runWhileAttached(chart, new Runnable() {

        @Override
        public void run() {
            cal.setTimeInMillis(System.currentTimeMillis());
            double hours = cal.get(Calendar.HOUR);
            double mins = cal.get(Calendar.MINUTE);
            double secs = cal.get(Calendar.SECOND);
            // disable animation when the second dial reaches 0
            boolean animation = secs == 0 ? false : true;
            configuration.getChart().setAnimation(animation);
            hour.setY(hours + (mins / 60.0));
            minute.setY(mins * (12.0 / 60.0) + secs * (12.0 / 3600.0));
            second.setY(secs * (12.0 / 60.0));
            series.update(hour);
            series.update(minute);
            series.update(second);
        }
    }, 1000, 15000);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) Calendar(java.util.Calendar) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Dial(com.vaadin.addon.charts.model.Dial) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) 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)

Example 29 with Labels

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

the class BasicLineWithTickCount method getChart.

@Override
protected Component getChart() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(false);
    layout.setMargin(false);
    final Chart chart = new Chart(ChartType.LINE);
    chart.setHeight("400px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    XAxis xAxis = configuration.getxAxis();
    Labels xLabels = new Labels();
    xLabels.setAutoRotation(new Number[] { -10, -20, -30, -40, 50, -60, -70, -80, -90 });
    xAxis.setLabels(xLabels);
    final YAxis yAxis = configuration.getyAxis();
    yAxis.setTickAmount(10);
    ListSeries ls = new ListSeries();
    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);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("New York");
    ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
    configuration.addSeries(ls);
    layout.addComponent(chart);
    final Slider slider = new Slider("Tick count (2 - 16)", 2, 16);
    slider.setWidth("200px");
    slider.setValue(10d);
    layout.addComponent(slider);
    layout.addComponent(new Button("Set max amount", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            slider.setValue(16d);
        }
    }));
    slider.addValueChangeListener(event -> {
        double newValue = slider.getValue();
        yAxis.setTickAmount(newValue);
        chart.drawChart();
    });
    return layout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Slider(com.vaadin.ui.Slider) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) Labels(com.vaadin.addon.charts.model.Labels) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

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