Exemplo n.º 1
0
 private void zoomTo(ZoomCoordinates zoom) {
   XAxis xAxis = chart.getConfiguration().getxAxis();
   YAxis yAxis = chart.getConfiguration().getyAxis();
   xAxis.setExtremes(zoom.xMin, zoom.xMax);
   yAxis.setExtremes(zoom.yMin, zoom.yMax);
   System.out.println("Setting zooms: " + zoom.xMin + " - " + zoom.xMax);
 }
Exemplo n.º 2
0
  private Chart createChart(int points) {
    Chart chart = new Chart(ChartType.SCATTER);
    Configuration conf = chart.getConfiguration();

    conf.getChart().setZoomType(ZoomType.XY);
    conf.disableCredits();
    conf.setTitle("Height vs Weight");
    conf.setSubTitle("Polygon series in Vaadin Charts.");

    Tooltip tooltip = conf.getTooltip();
    tooltip.setHeaderFormat("{series.name}");
    tooltip.setPointFormat("{point.x} cm, {point.y} kg");

    XAxis xAxis = conf.getxAxis();
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    xAxis.setTitle("Height (cm)");

    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("Weight (kg)");

    AbstractLinePlotOptions plotOptions = new PlotOptionsScatter();
    plotOptions.setThreshold(0);
    DataSeries scatter = new DataSeries();
    scatter.setPlotOptions(plotOptions);
    scatter.setName("Observations");
    fillScatter(scatter, points);
    conf.addSeries(scatter);
    return chart;
  }
  protected Component getChart() {
    final Chart chart = new Chart();
    chart.setWidth("500px");

    final Configuration configuration = new Configuration();
    configuration.getChart().setType(ChartType.GAUGE);
    configuration.getChart().setAlignTicks(false);
    configuration.getChart().setPlotBackgroundColor(null);
    configuration.getChart().setPlotBackgroundImage(null);
    configuration.getChart().setPlotBorderWidth(0);
    configuration.getChart().setPlotShadow(false);
    configuration.setTitle("Temperature");

    configuration.getPane().setStartAngle(-150);
    configuration.getPane().setEndAngle(150);

    YAxis yAxis = new YAxis();
    yAxis.setMin(-30);
    yAxis.setMax(50);
    yAxis.setLineColor(new SolidColor("#339"));
    yAxis.setTickColor(new SolidColor("#339"));
    yAxis.setMinorTickColor(new SolidColor("#339"));
    yAxis.setOffset(-25);
    yAxis.setLineWidth(2);
    yAxis.setLabels(new Labels());
    yAxis.getLabels().setDistance(-20);
    yAxis.getLabels().setRotationPerpendicular();
    yAxis.setTickLength(5);
    yAxis.setMinorTickLength(5);
    yAxis.setEndOnTick(false);

    configuration.addyAxis(yAxis);

    final ListSeries series = new ListSeries("Temperature", 12);

    PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
    plotOptionsGauge.setDataLabels(new Labels());
    plotOptionsGauge.getDataLabels().setFormatter("function() {return '' + this.y +  ' °C';}");
    GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1);
    gradient.addColorStop(0, new SolidColor("#DDD"));
    gradient.addColorStop(1, new SolidColor("#FFF"));
    plotOptionsGauge.getDataLabels().setBackgroundColor(gradient);
    plotOptionsGauge.getTooltip().setValueSuffix(" °C");
    series.setPlotOptions(plotOptionsGauge);
    configuration.setSeries(series);
    chart.drawChart(configuration);

    return chart;
  }