Package ofc

Source Code of ofc.OFCPieChartFactory

package ofc;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import jofc2.model.Chart;
import jofc2.model.elements.Element;
import jofc2.model.elements.PieChart;

import org.zkoss.zul.CategoryModel;

public class OFCPieChartFactory extends OFCChartFactory {

  public OFCPieChartFactory(OFC ofc) {
    super(ofc);
  }

  @Override
  public Chart createChart() {
    Chart chart = super.createChart();
    return chart;
  }

  /**
   * Generates the element to insert in the Chart
   *
   * @param ofc
   *            Chart object
   * @param model
   *
   * @return the generated element
   */
  @SuppressWarnings("unchecked")
  protected List<Element> createElements(OFC ofc, CategoryModel model) {
    PieChart e = new PieChart();

    if (ofc.getPallete() != null) {
      e.setColours(ofc.getPallete());
    }
    e.setGradientFill(true);
    // If the model have more than one series, only the first is used
    Comparable serie = model.getSeries(0);
    e.setText((String) serie);
    for (Iterator itCategories = model.getCategories().iterator(); itCategories
        .hasNext();) {
      Comparable category = (Comparable) itCategories.next();
      Number value = model.getValue(serie, category);
      e.addSlice(value, value.toString());
    }
    List<Element> elements = new ArrayList<Element>();
    elements.add(e);
    return elements;
  }

}
TOP

Related Classes of ofc.OFCPieChartFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.