Пример #1
0
  @Override
  protected Component getChart() {
    chart = new Chart();

    chart.getConfiguration().setTitle("Box Plot Example");

    Legend legend = new Legend();
    legend.setEnabled(false);
    chart.getConfiguration().setLegend(legend);

    XAxis xaxis = chart.getConfiguration().getxAxis();
    xaxis.setTitle("Experiment No.");
    xaxis.setCategories("1", "2", "3", "4", "5");

    YAxis yAxis = chart.getConfiguration().getyAxis();

    yAxis.setTitle("Observations");
    PlotLine plotLine = new PlotLine();
    plotLine.setColor(new SolidColor("red"));
    plotLine.setValue(932);
    plotLine.setWidth(1);
    PlotBandLabel label = new PlotBandLabel("Theoretical mean: 932");
    label.setAlign(HorizontalAlign.CENTER);
    Style style = new Style();
    style.setColor(new SolidColor("gray"));
    label.setStyle(style);
    plotLine.setLabel(label);
    yAxis.setPlotLines(plotLine);

    observations = new DataSeries();
    observations.setName("Observations");

    // Add PlotBoxItems contain all fields relevant for plot box chart
    observations.add(new BoxPlotItem(760, 801, 848, 895, 965));

    // Example with no arg constructor
    BoxPlotItem plotBoxItem = new BoxPlotItem();
    plotBoxItem.setLow(733);
    plotBoxItem.setLowerQuartile(853);
    plotBoxItem.setMedian(939);
    plotBoxItem.setUpperQuartile(980);
    plotBoxItem.setHigh(1080);
    observations.add(plotBoxItem);

    observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
    observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
    observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
    observations.setPlotOptions(getPlotBoxOptions());
    chart.getConfiguration().addSeries(observations);

    return chart;
  }
Пример #2
0
  @Test
  @Ignore("Phantomjs not installed on our build server")
  public void testWide() throws InterruptedException, URISyntaxException {

    Configuration conf = new Configuration();
    conf.getChart().setType(ChartType.COLUMN);
    conf.getChart().setMarginRight(200);
    Legend legend = conf.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.MIDDLE);
    legend.setBorderWidth(0);

    Random r = new Random();

    for (int i = 0; i < 20; i++) {
      String name = RandomStringUtils.randomAlphabetic(r.nextInt(20));
      DataSeries dataSeries = new DataSeries(name);
      dataSeries.add(new DataSeriesItem(name, r.nextInt(100)));
      conf.addSeries(dataSeries);
    }

    SVGGenerator instance = SVGGenerator.getInstance();
    String generatedSVG = instance.generate(conf, 1200, 400);

    Assert.assertTrue(generatedSVG.contains("width=\"1200\""));
    Assert.assertTrue(generatedSVG.contains("height=\"400\""));

    SVGGenerator.getInstance().destroy();
  }
Пример #3
0
  private void fillScatter(DataSeries series, int points) {
    Random random = new Random();
    for (int i = 0; i < points; i++) {
      double x = random.nextDouble() * 30 + 150;
      double y = 60;
      if (random.nextBoolean()) {
        y += random.nextDouble() * 15;
        if (random.nextBoolean() && x > 170) {
          y += random.nextDouble() * 30;
        }
      } else {
        y -= random.nextDouble() * 20;
      }
      x = Math.floor(x * 10) / 10;
      y = Math.floor(y * 10) / 10;

      int colorNumber = (int) Math.floor((x - 150) / 30 * 255);

      Color color = new SolidColor(colorNumber, 0, 255 - colorNumber);
      DataSeriesItem item = new DataSeriesItem(x, y);
      // item.setColor(color);
      series.add(item);
    }
  }