import org.knowm.xchart.PieChart;
import org.knowm.xchart.PieChartBuilder;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.style.Styler;

/**
 * Pie Chart with 4 Slices
 *
 * <p>Demonstrates the following:
 *
 * <ul>
 *   <li>Pie Chart
 *   <li>ChartBuilderPie
 *   <li>Setting Non-circular to match container aspect ratio
 *   <li>Legend outside south, with Horizontal Legend Layout
 */
public class xchart_pie {

  public static void main(String[] args) {
    PieChart chart = getChart();
    new SwingWrapper<>(chart).displayChart();
  }

  static public PieChart getChart() {

    // Create Chart
    PieChart chart =
        new PieChartBuilder().width(600).height(600).title("Pie Chart with 4 Slices").build();

    // Customize Chart
    chart.getStyler().setCircular(false);
    chart.getStyler().setLegendPosition(Styler.LegendPosition.OutsideS);
    chart.getStyler().setLegendLayout(Styler.LegendLayout.Horizontal);

    // Series
    chart.addSeries("Pennies", 100);
    chart.addSeries("Nickels", 200);
    chart.addSeries("Dimes", 600);
    chart.addSeries("Quarters", 100);

    return chart;
  }

}
