Search in sources :

Example 6 with YAxis

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

the class Flags method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.AREASPLINE);
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Average fruit consumption during one week");
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
    configuration.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle("Fruit units");
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setShared(true);
    tooltip.setValueSuffix(" units");
    configuration.setTooltip(tooltip);
    configuration.addSeries(new ListSeries("John", 3, 4, 3, 5, 4, 10, 12));
    ListSeries janeSeries = new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4);
    janeSeries.setId("jane");
    configuration.addSeries(janeSeries);
    DataSeries onSeriesFlags = new DataSeries("On series");
    PlotOptionsFlags onSeriesFlagsOptions = new PlotOptionsFlags();
    onSeriesFlagsOptions.setOnSeries("jane");
    onSeriesFlagsOptions.setShape(FlagShape.SQUAREPIN);
    onSeriesFlags.setPlotOptions(onSeriesFlagsOptions);
    onSeriesFlags.add(new FlagItem(2, "On series"));
    onSeriesFlags.add(new FlagItem(5, "On series"));
    configuration.addSeries(onSeriesFlags);
    DataSeries onAxisFlags = new DataSeries("On axis");
    onAxisFlags.setPlotOptions(new PlotOptionsFlags());
    onAxisFlags.add(new FlagItem(3, "On axis"));
    configuration.addSeries(onAxisFlags);
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) PlotOptionsFlags(com.vaadin.flow.component.charts.model.PlotOptionsFlags) FlagItem(com.vaadin.flow.component.charts.model.FlagItem) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 7 with YAxis

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

the class Gauge method initDemo.

@Override
public void initDemo() {
    // NOSONAR
    final Random random = new Random(0);
    final Chart chart = new Chart();
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.setTitle("Speedometer");
    configuration.getChart().setWidth(500);
    Pane pane = configuration.getPane();
    pane.setStartAngle(-150);
    pane.setEndAngle(150);
    YAxis yAxis = new YAxis();
    yAxis.setTitle("km/h");
    yAxis.setMin(0);
    yAxis.setMax(200);
    yAxis.setTickLength(10);
    yAxis.setTickPixelInterval(30);
    yAxis.setTickPosition(TickPosition.INSIDE);
    yAxis.setMinorTickLength(10);
    yAxis.setMinorTickInterval("auto");
    yAxis.setMinorTickPosition(TickPosition.INSIDE);
    Labels labels = new Labels();
    labels.setStep(2);
    labels.setRotation("auto");
    yAxis.setLabels(labels);
    PlotBand[] bands = new PlotBand[3];
    bands[0] = new PlotBand();
    bands[0].setFrom(0);
    bands[0].setTo(120);
    bands[0].setClassName("band-0");
    bands[1] = new PlotBand();
    bands[1].setFrom(120);
    bands[1].setTo(160);
    bands[1].setClassName("band-1");
    bands[2] = new PlotBand();
    bands[2].setFrom(160);
    bands[2].setTo(200);
    bands[2].setClassName("band-2");
    yAxis.setPlotBands(bands);
    configuration.addyAxis(yAxis);
    final ListSeries series = new ListSeries("Speed", 89);
    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    SeriesTooltip tooltip = new SeriesTooltip();
    tooltip.setValueSuffix(" km/h");
    plotOptionsGauge.setTooltip(tooltip);
    series.setPlotOptions(plotOptionsGauge);
    configuration.addSeries(series);
    runWhileAttached(chart, () -> {
        Integer oldValue = series.getData()[0].intValue();
        Integer newValue = (int) (oldValue + (random.nextDouble() - 0.5) * 20.0);
        series.updatePoint(0, newValue);
    }, 5000, 12000);
    add(chart);
}
Also used : PlotOptionsGauge(com.vaadin.flow.component.charts.model.PlotOptionsGauge) Random(java.util.Random) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Labels(com.vaadin.flow.component.charts.model.Labels) Pane(com.vaadin.flow.component.charts.model.Pane) PlotBand(com.vaadin.flow.component.charts.model.PlotBand) Chart(com.vaadin.flow.component.charts.Chart) YAxis(com.vaadin.flow.component.charts.model.YAxis) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Example 8 with YAxis

use of com.vaadin.flow.component.charts.model.YAxis 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 9 with YAxis

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

the class SVGGeneratorTest method createColumnWithoutTitle.

private Configuration createColumnWithoutTitle() {
    Configuration configuration = new Configuration();
    configuration.getChart().setType(ChartType.COLUMN);
    configuration.addSeries(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
    configuration.addSeries(new ListSeries("New York", 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3));
    configuration.addSeries(new ListSeries("London", 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2));
    configuration.addSeries(new ListSeries("Berlin", 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1));
    XAxis x = new XAxis();
    x.setCategories("January is a long month", "February is rather boring", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    configuration.addxAxis(x);
    YAxis y = new YAxis();
    y.setTitle("Rainfall (mm)");
    configuration.addyAxis(y);
    return configuration;
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 10 with YAxis

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

the class ConfigurationJSONSerializationTest method configurationJSONSerialization_configurationSerializedWithYAxis_yAxisConfigurationNotSerialized.

@Test
public void configurationJSONSerialization_configurationSerializedWithYAxis_yAxisConfigurationNotSerialized() {
    Configuration conf = new Configuration();
    YAxis axis = new YAxis();
    conf.addyAxis(axis);
    assertEquals("{\"chart\":{\"styledMode\":false},\"yAxis\":{\"axisIndex\":0},\"plotOptions\":{},\"series\":[],\"exporting\":{\"enabled\":false}}", toJSON(conf));
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) YAxis(com.vaadin.flow.component.charts.model.YAxis) Test(org.junit.Test)

Aggregations

YAxis (com.vaadin.flow.component.charts.model.YAxis)37 Configuration (com.vaadin.flow.component.charts.model.Configuration)32 Chart (com.vaadin.flow.component.charts.Chart)31 XAxis (com.vaadin.flow.component.charts.model.XAxis)27 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)21 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)17 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)15 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)11 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)10 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)10 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)9 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 Labels (com.vaadin.flow.component.charts.model.Labels)7 Pane (com.vaadin.flow.component.charts.model.Pane)4 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)4 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)4 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)4 Crosshair (com.vaadin.flow.component.charts.model.Crosshair)3 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)3