Search in sources :

Example 1 with Stop

use of com.vaadin.addon.charts.model.Stop 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 Stop

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

the class StopJSONSerializationTest method toJSON_axisWithStops_StopsCorrectlySerialized.

@Test
public void toJSON_axisWithStops_StopsCorrectlySerialized() {
    YAxis yaxis = new YAxis();
    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);
    // stops array should look like this
    // stops: [
    // [0.1, '#55BF3B'], // green
    // [0.5, '#DDDF0D'], // yellow
    // [0.9, '#DF5353'] // red
    // ]
    String expected = "{\"stops\":[[0.1,\"#008000\"],[0.5,\"#FFFF00\"],[0.9,\"#FF0000\"]]}";
    assertEquals(expected, toJSON(yaxis));
}
Also used : Stop(com.vaadin.addon.charts.model.Stop) YAxis(com.vaadin.addon.charts.model.YAxis) Test(org.junit.Test)

Example 3 with Stop

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

the class ChartTypes method chartTypesSolidGaugeAxisSnippet2.

public void chartTypesSolidGaugeAxisSnippet2() {
    YAxis yaxis = new YAxis();
    Chart chart = new Chart(ChartType.SOLIDGAUGE);
    Configuration conf = chart.getConfiguration();
    yaxis.setStops(new Stop(0.1f, SolidColor.GREEN), new Stop(0.5f, SolidColor.YELLOW), new Stop(0.9f, SolidColor.RED));
    conf.addyAxis(yaxis);
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Stop(com.vaadin.addon.charts.model.Stop) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Aggregations

Stop (com.vaadin.addon.charts.model.Stop)3 YAxis (com.vaadin.addon.charts.model.YAxis)3 Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 Background (com.vaadin.addon.charts.model.Background)1 DataLabels (com.vaadin.addon.charts.model.DataLabels)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 PlotOptionsSolidgauge (com.vaadin.addon.charts.model.PlotOptionsSolidgauge)1 SeriesTooltip (com.vaadin.addon.charts.model.SeriesTooltip)1 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)1 Random (java.util.Random)1 Test (org.junit.Test)1