Beispiel #1
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;
  }
Beispiel #2
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);
 }
Beispiel #3
0
 /**
  * Sets the y axis to linear or logarithmic.
  *
  * @param isLog true for log scale; false otherwise
  */
 public void setYLog(boolean isLog) {
   ylog = isLog; // Added by Paco
   if (isLog) {
     yaxis.setAxisType(XYAxis.LOG10);
   } else {
     yaxis.setAxisType(XYAxis.LINEAR);
   }
 }
Beispiel #4
0
 /**
  * Draws the axes in the drawing panel.
  *
  * @param panel
  * @param g
  */
 public void draw(DrawingPanel panel, Graphics g) {
   if (!visible) {
     return;
   }
   if (interiorColor != null) {
     g.setColor(interiorColor);
     int gw = panel.getLeftGutter() + panel.getRightGutter();
     int gh = panel.getTopGutter() + panel.getBottomGutter();
     g.fillRect(
         panel.getLeftGutter(),
         panel.getTopGutter(),
         panel.getWidth() - gw,
         panel.getHeight() - gh);
     g.setColor(Color.lightGray);
     g.drawRect(
         panel.getLeftGutter(),
         panel.getTopGutter(),
         panel.getWidth() - gw,
         panel.getHeight() - gh);
   }
   xaxis.draw(panel, g);
   yaxis.draw(panel, g);
   titleLine.setX((panel.getXMax() + panel.getXMin()) / 2);
   if (panel.getTopGutter() > 20) {
     titleLine.setY(panel.getYMax() + 5 / panel.getYPixPerUnit());
   } else {
     titleLine.setY(panel.getYMax() - 25 / panel.getYPixPerUnit());
   }
   titleLine.draw(panel, g);
 }
Beispiel #5
0
 @Test
 public void testPlotBandsWarning0() throws Exception {
   InterfaceLimit limit = new InterfaceLimit();
   limit.setWarning(0);
   limit.setCritical(50);
   ChartManager.setPlotBand(chart, limit);
   assertPlots(yAxis.getPlotBands(), 0, 0, 50, Integer.MAX_VALUE);
 }
Beispiel #6
0
 public Interactive findInteractive(DrawingPanel panel, int xpix, int ypix) {
   if (!visible) {
     return null;
   }
   if (xaxis.findInteractive(panel, xpix, ypix) != null) {
     return xaxis;
   } else if (yaxis.findInteractive(panel, xpix, ypix) != null) {
     return yaxis;
   } else {
     return null;
   }
 }
Beispiel #7
0
 /**
  * Constructs the XYAxes inside the drawing panel.
  *
  * <p>Drawing panel gutters are set to 30, 30, 30, 30.
  *
  * @param panel the drawing panel that will use the axes
  */
 public CartesianType3(PlottingPanel panel) {
   super(panel);
   defaultLeftGutter = 30;
   defaultTopGutter = 30;
   defaultRightGutter = 30;
   defaultBottomGutter = 30;
   titleLine.setJustification(TextLine.CENTER);
   titleLine.setFont(titleFont);
   xaxis = new XAxis();
   yaxis = new YAxis();
   xaxis.setEnabled(true); // enable dragging
   xaxis.setLocationType(XYAxis.DRAW_AT_LOCATION);
   yaxis.setEnabled(true);
   yaxis.setLocationType(XYAxis.DRAW_AT_LOCATION);
   if (panel == null) {
     return;
   }
   panel.setCoordinateStringBuilder(CoordinateStringBuilder.createCartesian());
   panel.setPreferredGutters(
       defaultLeftGutter, defaultTopGutter, defaultRightGutter, defaultBottomGutter);
   panel.setAxes(this);
 }
Beispiel #8
0
 @Test
 public void testArithmeticType() throws Exception {
   ChartManager.setLogarithmic(chart, false);
   assertNull(yAxis.getType());
 }
Beispiel #9
0
 @Test
 public void testLogarithmicType() throws Exception {
   ChartManager.setLogarithmic(chart, true);
   assertEquals(AxisType.LOGARITHMIC, yAxis.getType());
 }
Beispiel #10
0
 @Test
 public void testPlotBandsNull() throws Exception {
   ChartManager.setPlotBand(chart, null);
   assertPlots(yAxis.getPlotBands(), 0);
 }
Beispiel #11
0
 @Test
 public void testLogarithmicMin() throws Exception {
   ChartManager.setLogarithmic(chart, true);
   assertNull(yAxis.getMin());
 }
Beispiel #12
0
 public void setX(double x) {
   yaxis.setLocation(x); // Added by Paco
 }
Beispiel #13
0
 public void setXY(double x, double y) {
   xaxis.setLocation(y); // Added by Paco
   yaxis.setLocation(x); // Added by Paco
 }
Beispiel #14
0
 public void centerAxes(DrawingPanel panel) {
   xaxis.setLocation((panel.getYMax() + panel.getYMin()) / 2);
   yaxis.setLocation((panel.getXMax() + panel.getXMin()) / 2);
 }
Beispiel #15
0
 /** Shows a grid line for every y axis major tickmark. */
 public void setShowMajorYGrid(boolean showGrid) {
   yaxis.setShowMajorGrid(showGrid);
   if (!showGrid) {
     setShowMinorYGrid(showGrid);
   }
 }
Beispiel #16
0
 @Test
 public void testLogarithmicMinorTickInterval() throws Exception {
   ChartManager.setLogarithmic(chart, true);
   assertEquals(0.1, yAxis.getMinorTickInterval());
 }
Beispiel #17
0
 @Test
 public void testArithmeticMinorTickInterval() throws Exception {
   ChartManager.setLogarithmic(chart, false);
   assertNull(yAxis.getMinorTickInterval());
 }
Beispiel #18
0
 /**
  * Sets the y label of the axes. The font names understood are those understood by
  * java.awt.Font.decode(). If the font name is null, the font remains unchanged.
  *
  * @param s the title
  * @param font_name an optional font name
  */
 public void setYLabel(String s, String font_name) {
   yaxis.setTitle(s, font_name);
 }
Beispiel #19
0
 @Test
 public void testArithmeticMin() throws Exception {
   ChartManager.setLogarithmic(chart, false);
   assertEquals(0, yAxis.getMin());
 }
  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;
  }