예제 #1
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();
  }
예제 #2
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;
  }
예제 #3
0
  private Configuration createConf() {
    Configuration conf = new Configuration();

    conf.setTitle("Historic World Population by Region");
    conf.setSubTitle("Source: Wikipedia.org");

    XAxis x = new XAxis();
    x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
    x.setTitle((String) null);
    conf.addxAxis(x);

    YAxis y = new YAxis();
    y.setMin(0);
    Title title = new Title("Population (millions)");
    title.setVerticalAlign(VerticalAlign.HIGH);
    y.setTitle(title);
    conf.addyAxis(y);

    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
    conf.setTooltip(tooltip);

    PlotOptionsBar plot = new PlotOptionsBar();
    plot.setDataLabels(new Labels(true));
    conf.setPlotOptions(plot);

    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-100);
    legend.setY(100);
    legend.setFloating(true);
    legend.setBorderWidth(1);
    legend.setBackgroundColor("#FFFFFF");
    legend.setShadow(true);
    conf.setLegend(legend);

    conf.disableCredits();

    List<Series> series = new ArrayList<Series>();
    series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
    series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
    series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
    conf.setSeries(series);
    return conf;
  }
예제 #4
0
  public void configurarLegend() {
    Legend legend = getConfiguration().getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);

    legend.setX(-10d);
    legend.setY(100d);
    legend.setBorderWidth(0);
  }
예제 #5
0
  @Override
  protected Component getChart() {
    Chart chart = new Chart(ChartType.AREA);

    Configuration conf = chart.getConfiguration();

    conf.getChart().setInverted(true);

    conf.setTitle(new Title("Average fruit consumption during one week"));

    XAxis xAxis = new XAxis();
    xAxis.setCategories(
        "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
    conf.addxAxis(xAxis);

    YAxis yAxis = new YAxis();
    yAxis.setTitle(new Title("Number of units"));
    yAxis.setMin(0);
    conf.addyAxis(yAxis);

    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-150);
    legend.setY(100);
    legend.setBorderWidth(1);
    legend.setBackgroundColor("#ffffff");
    conf.setLegend(legend);

    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setFillOpacity(0.5);
    conf.setPlotOptions(plotOptions);

    conf.addSeries(new ListSeries("John", 3, 4, 3, 5, 4, 10, 12));
    conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));

    chart.drawChart(conf);

    return chart;
  }