Search in sources :

Example 1 with PlotOptionsSeries

use of com.vaadin.flow.component.charts.model.PlotOptionsSeries in project flow-components by vaadin.

the class Polar method initDemo.

@Override
public void initDemo() {
    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);
    XAxis xAxis = new XAxis();
    xAxis.setTickInterval(45);
    xAxis.setMin(0);
    xAxis.setMax(360);
    Labels labels = new Labels();
    labels.setFormatter("function() {return this.value + '°';}");
    xAxis.setLabels(labels);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    conf.addxAxis(xAxis);
    conf.addyAxis(yAxis);
    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);
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) PlotOptionsLine(com.vaadin.flow.component.charts.model.PlotOptionsLine) PlotOptionsArea(com.vaadin.flow.component.charts.model.PlotOptionsArea) Labels(com.vaadin.flow.component.charts.model.Labels) Pane(com.vaadin.flow.component.charts.model.Pane) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 2 with PlotOptionsSeries

use of com.vaadin.flow.component.charts.model.PlotOptionsSeries in project flow-components by vaadin.

the class DynamicChangingChart method getPolarConfiguration.

public Configuration getPolarConfiguration() {
    Configuration configuration = new Configuration();
    configuration.getChart().setPolar(true);
    configuration.setTitle("Polar Chart");
    Pane pane = new Pane(0, 360);
    configuration.addPane(pane);
    XAxis xAxis = new XAxis();
    xAxis.setTickInterval(45);
    xAxis.setMin(0);
    xAxis.setMax(360);
    Labels labels = new Labels();
    labels.setFormatter("function() {return this.value + '°';}");
    xAxis.setLabels(labels);
    YAxis yAxis = new YAxis();
    yAxis.setMin(0);
    configuration.addxAxis(xAxis);
    configuration.addyAxis(yAxis);
    PlotOptionsSeries series = new PlotOptionsSeries();
    PlotOptionsColumn column = new PlotOptionsColumn();
    series.setPointStart(0);
    series.setPointInterval(45);
    column.setPointPadding(0);
    column.setGroupPadding(0);
    configuration.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());
    configuration.setSeries(col, line, area);
    return configuration;
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) PlotOptionsLine(com.vaadin.flow.component.charts.model.PlotOptionsLine) PlotOptionsArea(com.vaadin.flow.component.charts.model.PlotOptionsArea) Labels(com.vaadin.flow.component.charts.model.Labels) Pane(com.vaadin.flow.component.charts.model.Pane) XAxis(com.vaadin.flow.component.charts.model.XAxis) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 3 with PlotOptionsSeries

use of com.vaadin.flow.component.charts.model.PlotOptionsSeries in project flow-components by vaadin.

the class GlobalOptions method initDemo.

@Override
public void initDemo() {
    List<Chart> charts = new ArrayList();
    NativeButton changeTitleButton = new NativeButton();
    changeTitleButton.setId("add_chart");
    changeTitleButton.setText("Add chart");
    changeTitleButton.addClickListener(e -> {
        final Chart chart = new Chart();
        Configuration configuration = chart.getConfiguration();
        configuration.setTitle("First Chart for Flow");
        chart.getConfiguration().getChart().setType(ChartType.AREA);
        Tooltip tooltip = configuration.getTooltip();
        tooltip.setEnabled(true);
        tooltip.setShared(true);
        PlotOptionsSeries options = new PlotOptionsSeries();
        options.setPointStart(0);
        options.setPointIntervalUnit(IntervalUnit.DAY);
        configuration.setPlotOptions(options);
        configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
        configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
        XAxis x = new XAxis();
        x.setType(AxisType.DATETIME);
        x.getLabels().setFormat("{value:%a}");
        configuration.addxAxis(x);
        YAxis y = new YAxis();
        y.setMin(0);
        y.setTitle("Rainfall (mm)");
        configuration.addyAxis(y);
        charts.add(chart);
        add(chart);
    });
    add(changeTitleButton);
    NativeButton changeLangButton = new NativeButton();
    changeLangButton.setId("change_lang");
    changeLangButton.setText("Change lang");
    changeLangButton.addClickListener(e -> {
        Lang lang = new Lang();
        lang.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
        lang.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
        lang.setWeekdays(new String[] { "Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai" });
        lang.setShortWeekdays(new String[] { "su", "ma", "ti", "ke", "to", "pe", "la" });
        ChartOptions.get().setLang(lang);
    });
    add(changeLangButton);
    NativeButton changeThemeLightButton = new NativeButton();
    changeThemeLightButton.setId("change_theme_light");
    changeThemeLightButton.setText("Change theme light");
    changeThemeLightButton.addClickListener(e -> {
        ChartOptions.get().setTheme(new LumoLightTheme());
        for (Chart chart : charts) {
            chart.drawChart(true);
        }
    });
    add(changeThemeLightButton);
    NativeButton changeThemeDarkButton = new NativeButton();
    changeThemeDarkButton.setId("change_theme_dark");
    changeThemeDarkButton.setText("Change theme Dark");
    changeThemeDarkButton.addClickListener(e -> {
        ChartOptions.get().setTheme(new LumoDarkTheme());
        for (Chart chart : charts) {
            chart.drawChart(true);
        }
    });
    add(changeThemeDarkButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Configuration(com.vaadin.flow.component.charts.model.Configuration) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) ArrayList(java.util.ArrayList) Lang(com.vaadin.flow.component.charts.model.Lang) XAxis(com.vaadin.flow.component.charts.model.XAxis) LumoDarkTheme(com.vaadin.flow.component.charts.themes.LumoDarkTheme) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) LumoLightTheme(com.vaadin.flow.component.charts.themes.LumoLightTheme) Chart(com.vaadin.flow.component.charts.Chart) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 4 with PlotOptionsSeries

use of com.vaadin.flow.component.charts.model.PlotOptionsSeries in project flow-components by vaadin.

the class AbstractSeriesBeanSerializer method serialize.

@Override
public void serialize(AbstractSeries bean, BeanSerializerDelegator<AbstractSeries> serializer, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    AbstractSeries series = bean;
    jgen.writeStartObject();
    // write other fields as per normal serialization rules
    serializer.serializeFields(bean, jgen, provider);
    if (series.getPlotOptions() != null && !(bean.getPlotOptions() instanceof PlotOptionsSeries)) {
        jgen.writeObjectField("type", series.getPlotOptions().getChartType());
    }
    jgen.writeEndObject();
}
Also used : AbstractSeries(com.vaadin.flow.component.charts.model.AbstractSeries) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries)

Example 5 with PlotOptionsSeries

use of com.vaadin.flow.component.charts.model.PlotOptionsSeries in project flow-components by vaadin.

the class DataProviderSeriesBeanSerializer method serialize.

@Override
public void serialize(DataProviderSeries bean, BeanSerializerDelegator<DataProviderSeries> serializer, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeStartObject();
    if (bean.getPlotOptions() != null && !(bean.getPlotOptions() instanceof PlotOptionsSeries)) {
        jgen.writeObjectField("type", bean.getPlotOptions().getChartType());
    }
    // write other fields as per normal serialization rules
    serializer.serializeFields(bean, jgen, provider);
    ArrayNode data = createDataArray(bean);
    jgen.writeObjectField("data", data);
    jgen.writeEndObject();
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries)

Aggregations

PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)11 Configuration (com.vaadin.flow.component.charts.model.Configuration)9 YAxis (com.vaadin.flow.component.charts.model.YAxis)9 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)7 Chart (com.vaadin.flow.component.charts.Chart)6 XAxis (com.vaadin.flow.component.charts.model.XAxis)6 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)5 Labels (com.vaadin.flow.component.charts.model.Labels)3 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)2 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)2 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)2 Legend (com.vaadin.flow.component.charts.model.Legend)2 Pane (com.vaadin.flow.component.charts.model.Pane)2 PlotLine (com.vaadin.flow.component.charts.model.PlotLine)2 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)2 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)2 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)1 AbstractSeries (com.vaadin.flow.component.charts.model.AbstractSeries)1