Search in sources :

Example 1 with Pane

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

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

the class SolidGauge method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.SOLIDGAUGE);
    Configuration configuration = chart.getConfiguration();
    Pane pane = configuration.getPane();
    pane.setCenter(new String[] { "50%", "50%" });
    pane.setStartAngle(-90);
    pane.setEndAngle(90);
    Background paneBackground = new Background();
    paneBackground.setInnerRadius("60%");
    paneBackground.setOuterRadius("100%");
    paneBackground.setShape(BackgroundShape.ARC);
    pane.setBackground(paneBackground);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTickAmount(2);
    yAxis.setTitle("Speed");
    yAxis.setMinorTickInterval("null");
    yAxis.getTitle().setY(-50);
    yAxis.getLabels().setY(16);
    yAxis.setMin(0);
    yAxis.setMax(200);
    PlotOptionsSolidgauge plotOptionsSolidgauge = new PlotOptionsSolidgauge();
    DataLabels dataLabels = plotOptionsSolidgauge.getDataLabels();
    dataLabels.setY(5);
    dataLabels.setUseHTML(true);
    configuration.setPlotOptions(plotOptionsSolidgauge);
    DataSeries series = new DataSeries("Speed");
    DataSeriesItem item = new DataSeriesItem();
    item.setY(80);
    // item.setColorIndex(2);
    item.setClassName("myClassName");
    DataLabels dataLabelsSeries = new DataLabels();
    dataLabelsSeries.setFormat("<div style=\"text-align:center\"><span style=\"font-size:25px;" + "color:black' + '\">{y}</span><br/>" + "<span style=\"font-size:12px;color:silver\">km/h</span></div>");
    item.setDataLabels(dataLabelsSeries);
    series.add(item);
    configuration.addSeries(series);
    add(chart);
}
Also used : DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Configuration(com.vaadin.flow.component.charts.model.Configuration) Background(com.vaadin.flow.component.charts.model.Background) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Pane(com.vaadin.flow.component.charts.model.Pane) PlotOptionsSolidgauge(com.vaadin.flow.component.charts.model.PlotOptionsSolidgauge) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 3 with Pane

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

use of com.vaadin.flow.component.charts.model.Pane 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)

Aggregations

Configuration (com.vaadin.flow.component.charts.model.Configuration)4 Pane (com.vaadin.flow.component.charts.model.Pane)4 YAxis (com.vaadin.flow.component.charts.model.YAxis)4 Chart (com.vaadin.flow.component.charts.Chart)3 Labels (com.vaadin.flow.component.charts.model.Labels)3 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)3 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 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)2 XAxis (com.vaadin.flow.component.charts.model.XAxis)2 Background (com.vaadin.flow.component.charts.model.Background)1 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)1 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)1 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)1 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)1 PlotOptionsGauge (com.vaadin.flow.component.charts.model.PlotOptionsGauge)1 PlotOptionsSolidgauge (com.vaadin.flow.component.charts.model.PlotOptionsSolidgauge)1 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)1 Random (java.util.Random)1