Search in sources :

Example 1 with PlotOptionsSolidgauge

use of com.vaadin.addon.charts.model.PlotOptionsSolidgauge in project charts by vaadin.

the class SolidGauge method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth(500, Unit.PIXELS);
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SOLIDGAUGE);
    configuration.getTitle().setText("Speed");
    Pane pane = new Pane();
    pane.setCenter("50%", "85%");
    pane.setSize("140%");
    pane.setStartAngle(-90);
    pane.setEndAngle(90);
    configuration.addPane(pane);
    configuration.getTooltip().setEnabled(false);
    Background bkg = new Background();
    bkg.setBackgroundColor(new SolidColor("#eeeeee"));
    bkg.setInnerRadius("60%");
    bkg.setOuterRadius("100%");
    bkg.setShape("arc");
    bkg.setBorderWidth(0);
    pane.setBackground(bkg);
    YAxis yaxis = configuration.getyAxis();
    yaxis.setLineWidth(0);
    yaxis.setTickInterval(200);
    yaxis.setTickWidth(0);
    yaxis.setMin(0);
    yaxis.setMax(200);
    yaxis.setTitle("");
    yaxis.getTitle().setY(-70);
    yaxis.setLabels(new Labels());
    yaxis.getLabels().setY(16);
    Stop stop1 = new Stop(0.1f, SolidColor.GREEN);
    Stop stop2 = new Stop(0.5f, SolidColor.YELLOW);
    Stop stop3 = new Stop(0.9f, SolidColor.RED);
    yaxis.setStops(stop1, stop2, stop3);
    PlotOptionsSolidgauge plotOptions = new PlotOptionsSolidgauge();
    plotOptions.setTooltip(new SeriesTooltip());
    plotOptions.getTooltip().setValueSuffix(" km/h");
    DataLabels labels = new DataLabels();
    labels.setY(5);
    labels.setBorderWidth(0);
    labels.setUseHTML(true);
    labels.setFormat("<div style=\"text-align:center\"><span style=\"font-size:25px;\">{y}</span><br/>" + "                       <span style=\"font-size:12pxg\">km/h</span></div>");
    plotOptions.setDataLabels(labels);
    configuration.setPlotOptions(plotOptions);
    final ListSeries series = new ListSeries("Speed", 80);
    configuration.setSeries(series);
    runWhileAttached(chart, new Runnable() {

        Random r = new Random(0);

        @Override
        public void run() {
            Integer oldValue = series.getData()[0].intValue();
            Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
            if (newValue > 200) {
                newValue = 200;
            } else if (newValue < 0) {
                newValue = 0;
            }
            series.updatePoint(0, newValue);
        }
    }, 3000, 12000);
    chart.drawChart(configuration);
    return chart;
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) Background(com.vaadin.addon.charts.model.Background) Stop(com.vaadin.addon.charts.model.Stop) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) DataLabels(com.vaadin.addon.charts.model.DataLabels) Labels(com.vaadin.addon.charts.model.Labels) Pane(com.vaadin.addon.charts.model.Pane) Random(java.util.Random) ListSeries(com.vaadin.addon.charts.model.ListSeries) PlotOptionsSolidgauge(com.vaadin.addon.charts.model.PlotOptionsSolidgauge) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

Example 2 with PlotOptionsSolidgauge

use of com.vaadin.addon.charts.model.PlotOptionsSolidgauge in project charts by vaadin.

the class ChartTypes method chartTypesSolidGaugePlotoptionsSnippet1.

public void chartTypesSolidGaugePlotoptionsSnippet1() {
    Chart chart = new Chart(ChartType.SOLIDGAUGE);
    Configuration conf = chart.getConfiguration();
    PlotOptionsSolidgauge options = new PlotOptionsSolidgauge();
    // Move the value display box at the center a bit higher
    DataLabels dataLabels = new DataLabels();
    dataLabels.setY(-20);
    options.setDataLabels(dataLabels);
    conf.setPlotOptions(options);
}
Also used : DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsSolidgauge(com.vaadin.addon.charts.model.PlotOptionsSolidgauge) Chart(com.vaadin.addon.charts.Chart)

Aggregations

Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 DataLabels (com.vaadin.addon.charts.model.DataLabels)2 PlotOptionsSolidgauge (com.vaadin.addon.charts.model.PlotOptionsSolidgauge)2 Background (com.vaadin.addon.charts.model.Background)1 Labels (com.vaadin.addon.charts.model.Labels)1 ListSeries (com.vaadin.addon.charts.model.ListSeries)1 Pane (com.vaadin.addon.charts.model.Pane)1 SeriesTooltip (com.vaadin.addon.charts.model.SeriesTooltip)1 Stop (com.vaadin.addon.charts.model.Stop)1 YAxis (com.vaadin.addon.charts.model.YAxis)1 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)1 Random (java.util.Random)1