Search in sources :

Example 1 with PlotOptionsPie

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

the class PieWithLegend method initDemo.

@Override
public void initDemo() {
    chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares in January, 2018");
    Tooltip tooltip = new Tooltip();
    tooltip.setValueDecimals(1);
    conf.setTooltip(tooltip);
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setAllowPointSelect(true);
    plotOptions.setCursor(Cursor.POINTER);
    plotOptions.setShowInLegend(true);
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries();
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 61.41);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Internet Explorer", 11.84));
    series.add(new DataSeriesItem("Firefox", 10.85));
    series.add(new DataSeriesItem("Edge", 4.67));
    series.add(new DataSeriesItem("Safari", 4.18));
    series.add(new DataSeriesItem("Sogou Explorer", 1.64));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("QQ", 1.2));
    series.add(new DataSeriesItem("Others", 2.61));
    conf.setSeries(series);
    chart.setVisibilityTogglingDisabled(true);
    listenerRegistration = chart.addPointLegendItemClickListener(event -> {
        showNotification("Legend item click" + " : " + event.getItemIndex() + " : " + event.getItem().getName());
    });
    add(chart);
}
Also used : DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) ChartType(com.vaadin.flow.component.charts.model.ChartType) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Chart(com.vaadin.flow.component.charts.Chart) Registration(com.vaadin.flow.shared.Registration) PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) AbstractChartExample(com.vaadin.flow.component.charts.examples.AbstractChartExample) Cursor(com.vaadin.flow.component.charts.model.Cursor) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) Configuration(com.vaadin.flow.component.charts.model.Configuration) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 2 with PlotOptionsPie

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

the class ConfigurationJSONSerializationTest method configurationJSONSerialization_setOptionsWithInactiveState_inactiveStatesSerialized.

@Test
public void configurationJSONSerialization_setOptionsWithInactiveState_inactiveStatesSerialized() {
    Configuration conf = new Configuration();
    PlotOptionsPie options = new PlotOptionsPie();
    States states = options.getStates();
    Inactive inactive = states.getInactive();
    inactive.setOpacity(1.0);
    inactive.setBorderColor(new SolidColor("#000000"));
    inactive.setColor(new SolidColor("#808080"));
    inactive.setAnimation(false);
    conf.setPlotOptions(options);
    assertEquals("{\"chart\":{\"styledMode\":false},\"plotOptions\":{\"pie\":{\"states\":{\"inactive\":{\"animation\":false,\"borderColor\":\"#000000\",\"color\":\"#808080\",\"opacity\":1.0}}}},\"series\":[],\"exporting\":{\"enabled\":false}}", toJSON(conf));
}
Also used : States(com.vaadin.flow.component.charts.model.States) PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) Configuration(com.vaadin.flow.component.charts.model.Configuration) Inactive(com.vaadin.flow.component.charts.model.Inactive) SolidColor(com.vaadin.flow.component.charts.model.style.SolidColor) Test(org.junit.Test)

Example 3 with PlotOptionsPie

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

the class ColumnLineAndPie method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Combined Chart");
    conf.setExporting(true);
    XAxis x = new XAxis();
    x.setCategories(new String[] { "Apples", "Oranges", "Pears", "Bananas", "Plums" });
    conf.addxAxis(x);
    Style labelStyle = new Style();
    labelStyle.setTop("8px");
    labelStyle.setLeft("40px");
    conf.setLabels(new HTMLLabels(labelStyle, new HTMLLabelItem("Total fruit consumption")));
    DataSeries series = new DataSeries();
    PlotOptionsColumn plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("Jane");
    series.setData(3, 2, 1, 3, 4);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("John");
    series.setData(2, 3, 5, 7, 6);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("Joe");
    series.setData(4, 3, 3, 9, 0);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline splinePlotOptions = new PlotOptionsSpline();
    series.setPlotOptions(splinePlotOptions);
    series.setName("Average");
    series.setData(3, 2.67, 3, 6.33, 3.33);
    conf.addSeries(series);
    series = new DataSeries();
    series.setPlotOptions(new PlotOptionsPie());
    series.setName("Total consumption");
    DataSeriesItem item = new DataSeriesItem("Jane", 13);
    series.add(item);
    item = new DataSeriesItem("John", 23);
    series.add(item);
    item = new DataSeriesItem("Joe", 19);
    series.add(item);
    PlotOptionsPie plotOptionsPie = new PlotOptionsPie();
    plotOptionsPie.setSize("100px");
    plotOptionsPie.setCenter("100px", "80px");
    plotOptionsPie.setShowInLegend(false);
    series.setPlotOptions(plotOptionsPie);
    conf.addSeries(series);
    add(chart);
}
Also used : HTMLLabelItem(com.vaadin.flow.component.charts.model.HTMLLabelItem) PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Style(com.vaadin.flow.component.charts.model.style.Style) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotOptionsSpline(com.vaadin.flow.component.charts.model.PlotOptionsSpline) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) HTMLLabels(com.vaadin.flow.component.charts.model.HTMLLabels)

Example 4 with PlotOptionsPie

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

the class SVGGeneratorTest method createPieChartConfiguration.

private Configuration createPieChartConfiguration() {
    Configuration conf = new Configuration();
    conf.setTitle("Browser market shares in January, 2018");
    conf.getChart().setType(ChartType.PIE);
    Tooltip tooltip = new Tooltip();
    tooltip.setValueDecimals(1);
    conf.setTooltip(tooltip);
    PlotOptionsPie plotOptions = new PlotOptionsPie();
    plotOptions.setAllowPointSelect(true);
    plotOptions.setCursor(Cursor.POINTER);
    plotOptions.setShowInLegend(true);
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries();
    DataSeriesItem chrome = new DataSeriesItem("Chrome", 61.41);
    chrome.setSliced(true);
    chrome.setSelected(true);
    series.add(chrome);
    series.add(new DataSeriesItem("Internet Explorer", 11.84));
    series.add(new DataSeriesItem("Firefox", 10.85));
    series.add(new DataSeriesItem("Edge", 4.67));
    series.add(new DataSeriesItem("Safari", 4.18));
    series.add(new DataSeriesItem("Sogou Explorer", 1.64));
    series.add(new DataSeriesItem("Opera", 6.2));
    series.add(new DataSeriesItem("QQ", 1.2));
    series.add(new DataSeriesItem("Others", 2.61));
    conf.setSeries(series);
    return conf;
}
Also used : PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) Configuration(com.vaadin.flow.component.charts.model.Configuration) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Aggregations

Configuration (com.vaadin.flow.component.charts.model.Configuration)4 PlotOptionsPie (com.vaadin.flow.component.charts.model.PlotOptionsPie)4 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)3 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)3 Chart (com.vaadin.flow.component.charts.Chart)2 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)2 AbstractChartExample (com.vaadin.flow.component.charts.examples.AbstractChartExample)1 ChartType (com.vaadin.flow.component.charts.model.ChartType)1 Cursor (com.vaadin.flow.component.charts.model.Cursor)1 HTMLLabelItem (com.vaadin.flow.component.charts.model.HTMLLabelItem)1 HTMLLabels (com.vaadin.flow.component.charts.model.HTMLLabels)1 Inactive (com.vaadin.flow.component.charts.model.Inactive)1 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)1 PlotOptionsSpline (com.vaadin.flow.component.charts.model.PlotOptionsSpline)1 States (com.vaadin.flow.component.charts.model.States)1 XAxis (com.vaadin.flow.component.charts.model.XAxis)1 SolidColor (com.vaadin.flow.component.charts.model.style.SolidColor)1 Style (com.vaadin.flow.component.charts.model.style.Style)1 Registration (com.vaadin.flow.shared.Registration)1 Test (org.junit.Test)1