Search in sources :

Example 1 with Background

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

Aggregations

Chart (com.vaadin.flow.component.charts.Chart)1 Background (com.vaadin.flow.component.charts.model.Background)1 Configuration (com.vaadin.flow.component.charts.model.Configuration)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 Pane (com.vaadin.flow.component.charts.model.Pane)1 PlotOptionsSolidgauge (com.vaadin.flow.component.charts.model.PlotOptionsSolidgauge)1 YAxis (com.vaadin.flow.component.charts.model.YAxis)1