Search in sources :

Example 41 with Configuration

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

Example 42 with Configuration

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

the class TimeSeriesIntervalUnit method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("Point interval test");
    configuration.getxAxis().setType(AxisType.DATETIME);
    final PlotOptionsSeries plotOptions = new PlotOptionsSeries();
    try {
        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        plotOptions.setPointStart(df.parse("20150101"));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    plotOptions.setPointInterval(1);
    plotOptions.setPointIntervalUnit(IntervalUnit.MONTH);
    configuration.setPlotOptions(plotOptions);
    ListSeries ls = new ListSeries();
    ls.setData(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    configuration.setSeries(ls);
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(false);
    layout.setMargin(false);
    layout.addComponent(chart);
    layout.addComponent(new Button("one day interval", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            plotOptions.setPointInterval(24 * 3600 * 1000);
            plotOptions.setPointIntervalUnit(null);
            chart.drawChart();
        }
    }));
    return layout;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Button(com.vaadin.ui.Button) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ClickEvent(com.vaadin.ui.Button.ClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.vaadin.addon.charts.Chart) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries)

Example 43 with Configuration

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

the class TimeSeriesZoomable method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Color[] colors = getThemeColors();
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setZoomType(ZoomType.X);
    configuration.getChart().setSpacingRight(20);
    configuration.getTitle().setText("USD to EUR exchange rate from 2006 through 2008");
    String title = Page.getCurrent().getWebBrowser().isTouchDevice() ? "Drag your finger over the plot to zoom in" : "Click and drag in the plot area to zoom in";
    configuration.getSubTitle().setText(title);
    configuration.getxAxis().setType(AxisType.DATETIME);
    configuration.getxAxis().setMinRange(TWO_WEEKS);
    configuration.getxAxis().setTitle(new AxisTitle(""));
    configuration.getLegend().setEnabled(false);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Exchange rate"));
    yAxis.setMin(0.6);
    yAxis.setStartOnTick(false);
    yAxis.setShowFirstLabel(false);
    configuration.getTooltip().setShared(true);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    GradientColor fillColor = GradientColor.createLinear(0, 0, 0, 1);
    fillColor.addColorStop(0, (SolidColor) colors[0]);
    fillColor.addColorStop(1, (SolidColor) colors[8]);
    plotOptions.setFillColor(fillColor);
    plotOptions.setLineWidth(1);
    plotOptions.setShadow(false);
    Marker marker = new Marker();
    marker.setEnabled(false);
    Hover hoverState = new Hover(true);
    hoverState.setRadius(5);
    States states = new States();
    states.setHover(hoverState);
    marker.setStates(states);
    Hover hoverStateForArea = new Hover(true);
    hoverStateForArea.setLineWidth(1);
    States statesForArea = new States();
    statesForArea.setHover(hoverStateForArea);
    plotOptions.setStates(statesForArea);
    plotOptions.setMarker(marker);
    plotOptions.setShadow(false);
    configuration.setPlotOptions(plotOptions);
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    ListSeries ls = new ListSeries();
    PlotOptionsArea options = new PlotOptionsArea();
    options.setPointInterval(DAY_IN_MILLIS);
    ls.setPlotOptions(options);
    ls.setName("USD to EUR");
    try {
        options.setPointStart(df.parse("2006/01/02").getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    ls.setData(USD_TO_EUR_EXCHANGE_RATES);
    configuration.setSeries(ls);
    chart.drawChart(configuration);
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) GradientColor(com.vaadin.addon.charts.model.style.GradientColor) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) Marker(com.vaadin.addon.charts.model.Marker) States(com.vaadin.addon.charts.model.States) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) ListSeries(com.vaadin.addon.charts.model.ListSeries) Hover(com.vaadin.addon.charts.model.Hover) ParseException(java.text.ParseException) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) SimpleDateFormat(java.text.SimpleDateFormat) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 44 with Configuration

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

the class AreaSplineSite method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREASPLINE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Monthly supply and demand");
    conf.setSubTitle("Last six months");
    Legend legend = conf.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(150);
    legend.setY(100);
    Tooltip tooltip = conf.getTooltip();
    tooltip.setValueSuffix("t");
    tooltip.setShared(true);
    XAxis xAxis = conf.getxAxis();
    xAxis.setCategories("January", "February", "March", "April", "May", "June");
    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("Metric tons");
    conf.addSeries(new ListSeries("Supply", 35, 28, 45, 60, 80, 74));
    conf.addSeries(new ListSeries("Demand", 29, 11, 50, 63, 65, 61));
    return chart;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) Tooltip(com.vaadin.addon.charts.model.Tooltip) Chart(com.vaadin.addon.charts.Chart) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 45 with Configuration

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

the class LibraryData method getChart.

@Override
protected Component getChart() {
    chart = new Chart(ChartType.BAR);
    chart.setSizeFull();
    Configuration config = chart.getConfiguration();
    boolean inverted = config.getChart().getInverted();
    config.getChart().setInverted(!inverted);
    config.getLegend().setEnabled(false);
    YAxis axis = new YAxis();
    axis.setTitle("Pages");
    config.addyAxis(axis);
    series = new DataSeries();
    config.setSeries(series);
    updateChart();
    return chart;
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Configuration (com.vaadin.addon.charts.model.Configuration)257 Chart (com.vaadin.addon.charts.Chart)196 YAxis (com.vaadin.addon.charts.model.YAxis)100 DataSeries (com.vaadin.addon.charts.model.DataSeries)72 ListSeries (com.vaadin.addon.charts.model.ListSeries)70 XAxis (com.vaadin.addon.charts.model.XAxis)65 Test (org.junit.Test)58 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)56 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)54 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)51 Tooltip (com.vaadin.addon.charts.model.Tooltip)42 DataLabels (com.vaadin.addon.charts.model.DataLabels)41 Legend (com.vaadin.addon.charts.model.Legend)30 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)30 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)27 Elements (org.jsoup.select.Elements)27 Marker (com.vaadin.addon.charts.model.Marker)22 DesignContext (com.vaadin.ui.declarative.DesignContext)22 Element (org.jsoup.nodes.Element)22 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)20