Search in sources :

Example 6 with AxisTitle

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

the class LineWithDashSelector method getChart.

@Override
protected Component getChart() {
    chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.LINE);
    configuration.getChart().setMarginRight(130);
    configuration.getChart().setMarginBottom(25);
    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.setMin(-5d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    plotOptions.setDashStyle(DashStyle.DOT);
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-10d);
    legend.setY(100d);
    legend.setBorderWidth(0);
    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);
    ls = new ListSeries();
    ls.setName("Berlin");
    ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
    configuration.addSeries(ls);
    ls = new ListSeries();
    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);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    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) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 7 with AxisTitle

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

Example 8 with AxisTitle

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

the class TimeDataWithIrregularIntervals 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("Snow depth in the Vikjafjellet mountain, Norway");
    configuration.getSubTitle().setText("An example of irregular time data in Highcharts JS");
    configuration.getTooltip().setFormatter("");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats("%e. %b", "%b"));
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Snow depth (m)"));
    yAxis.setMin(0);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>\'+ Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' m'");
    DataSeries ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2007-2008");
    Object[][] data1 = getData1();
    for (int i = 0; i < data1.length; i++) {
        Object[] ds = data1[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2008-2009");
    Object[][] data2 = getData2();
    for (int i = 0; i < data2.length; i++) {
        Object[] ds = data2[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    ls = new DataSeries();
    ls.setPlotOptions(new PlotOptionsSpline());
    ls.setName("Winter 2009-2010");
    Object[][] data3 = getData3();
    for (int i = 0; i < data3.length; i++) {
        Object[] ds = data3[i];
        DataSeriesItem item = new DataSeriesItem((Instant) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) DataSeries(com.vaadin.addon.charts.model.DataSeries) DateTimeLabelFormats(com.vaadin.addon.charts.model.DateTimeLabelFormats) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) 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 9 with AxisTitle

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

the class AngularGauge method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");
    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("Speedometer");
    GradientColor gradient1 = GradientColor.createLinear(0, 0, 0, 1);
    gradient1.addColorStop(0, new SolidColor("#FFF"));
    gradient1.addColorStop(1, new SolidColor("#333"));
    GradientColor gradient2 = GradientColor.createLinear(0, 0, 0, 1);
    gradient2.addColorStop(0, new SolidColor("#333"));
    gradient2.addColorStop(1, new SolidColor("#FFF"));
    Background[] background = new Background[3];
    background[0] = new Background();
    background[0].setBackgroundColor(gradient1);
    background[0].setBorderWidth(0);
    background[0].setOuterRadius("109%");
    background[1] = new Background();
    background[1].setBackgroundColor(gradient2);
    background[1].setBorderWidth(1);
    background[1].setOuterRadius("107%");
    background[2] = new Background();
    background[2].setBackgroundColor(new SolidColor("#DDD"));
    background[2].setBorderWidth(0);
    background[2].setInnerRadius("103%");
    background[2].setOuterRadius("105%");
    configuration.getPane().setStartAngle(-150);
    configuration.getPane().setEndAngle(150);
    configuration.getPane().setBackground(background);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("km/h"));
    yAxis.setMin(0);
    yAxis.setMax(200);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickWidth(1);
    yAxis.setMinorTickLength(10);
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    yAxis.setMinorTickColor(new SolidColor("#666"));
    yAxis.setGridLineWidth(0);
    yAxis.setTickPixelInterval(30);
    yAxis.setTickWidth(2);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setTickLength(10);
    yAxis.setTickColor(new SolidColor("#666"));
    Labels labels = new Labels();
    labels.setStep(2);
    labels.setRotationPerpendicular();
    yAxis.setLabels(labels);
    PlotBand[] plotBands = new PlotBand[3];
    plotBands[0] = new PlotBand(0, 120, new SolidColor("#55BF3B"));
    plotBands[1] = new PlotBand(120, 160, new SolidColor("#DDDF0D"));
    plotBands[2] = new PlotBand(160, 200, new SolidColor("#DF5353"));
    yAxis.setPlotBands(plotBands);
    final ListSeries series = new ListSeries("Speed", 80);
    PlotOptionsGauge plotOptions = new PlotOptionsGauge();
    plotOptions.setTooltip(new SeriesTooltip());
    plotOptions.getTooltip().setValueSuffix(" km/h");
    series.setPlotOptions(plotOptions);
    configuration.setSeries(series);
    runWhileAttached(chart, new Runnable() {

        Random r = new Random(0);

        @Override
        public void run() {
            Integer oldValue = series.getData()[0].intValue();
            Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
            series.updatePoint(0, newValue);
        }
    }, 3000, 12000);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) PlotOptionsGauge(com.vaadin.addon.charts.model.PlotOptionsGauge) Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) PlotBand(com.vaadin.addon.charts.model.PlotBand) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

Example 10 with AxisTitle

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

the class TimeDataWithIrregularIntervalsAndLocalizedTexts method getChart.

@Override
protected Component getChart() {
    // localizations
    final Lang fi = new Lang();
    fi.setDecimalPoint(",");
    fi.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
    fi.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
    fi.setWeekdays(new String[] { "Ma", "Ti", "Ke", "To", "Pe", "La", "Su" });
    final Lang en = new Lang();
    en.setDecimalPoint(".");
    en.setShortMonths(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" });
    en.setMonths(new String[] { "January", "February", "March", "April", "May", "June", "Jule", "August", "September", "October", "November", "December" });
    en.setWeekdays(new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" });
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Lumen syvyys Vikjafjellet-tunturilla, Norja");
    configuration.getSubTitle().setText("Lokalisointiesimerkki");
    configuration.getTooltip().setFormatter("");
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setDateTimeLabelFormats(new DateTimeLabelFormats());
    configuration.getxAxis().getDateTimeLabelFormats().setMonth("%B");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Lumen syvyys (m)"));
    yAxis.setMin(0);
    DataSeries ls = new DataSeries();
    PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
    plotOptionsSpline.setDataLabels(new DataLabels(true));
    plotOptionsSpline.setEnableMouseTracking(false);
    plotOptionsSpline.getDataLabels().setFormatter("return Highcharts.dateFormat('%a %d %B',this.x);");
    ls.setPlotOptions(plotOptionsSpline);
    ls.setName("Talvi 2009-2010");
    Object[][] data3 = getData3();
    for (int i = 0; i < data3.length; i++) {
        Object[] ds = data3[i];
        DataSeriesItem item = new DataSeriesItem((Date) ds[0], (Double) ds[1]);
        ls.add(item);
    }
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    final Button enButton = new Button("English");
    enButton.setId("en-button");
    enButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ChartOptions.get().setLang(en);
        }
    });
    final Button fiButton = new Button("Finnish");
    fiButton.setId("fi-button");
    fiButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ChartOptions.get().setLang(fi);
        }
    });
    HorizontalLayout horizontalLayout = new HorizontalLayout(enButton, fiButton);
    horizontalLayout.setSpacing(false);
    VerticalLayout verticalLayout = new VerticalLayout(horizontalLayout, chart);
    verticalLayout.setSpacing(false);
    verticalLayout.setMargin(false);
    return verticalLayout;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) ClickEvent(com.vaadin.ui.Button.ClickEvent) Lang(com.vaadin.addon.charts.model.Lang) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) DataSeries(com.vaadin.addon.charts.model.DataSeries) DateTimeLabelFormats(com.vaadin.addon.charts.model.DateTimeLabelFormats) 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)

Aggregations

AxisTitle (com.vaadin.addon.charts.model.AxisTitle)53 Configuration (com.vaadin.addon.charts.model.Configuration)52 YAxis (com.vaadin.addon.charts.model.YAxis)50 Chart (com.vaadin.addon.charts.Chart)49 ListSeries (com.vaadin.addon.charts.model.ListSeries)30 XAxis (com.vaadin.addon.charts.model.XAxis)26 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)25 DataLabels (com.vaadin.addon.charts.model.DataLabels)18 DataSeries (com.vaadin.addon.charts.model.DataSeries)18 Tooltip (com.vaadin.addon.charts.model.Tooltip)16 Legend (com.vaadin.addon.charts.model.Legend)15 Marker (com.vaadin.addon.charts.model.Marker)14 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)12 Labels (com.vaadin.addon.charts.model.Labels)12 Title (com.vaadin.addon.charts.model.Title)12 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)11 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)11 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)10 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)10 Hover (com.vaadin.addon.charts.model.Hover)9