Example #1
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;
  }
Example #2
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;
  }