Package ofc

Source Code of ofc.OFCBarChartFactory

package ofc;

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

import jofc2.model.Chart;
import jofc2.model.axis.Label;
import jofc2.model.axis.XAxis;
import jofc2.model.axis.YAxis;
import jofc2.model.elements.Element;
import jofc2.model.elements.FilledBarChart;

import org.zkoss.zul.CategoryModel;

public class OFCBarChartFactory extends OFCChartFactory {
  public OFCBarChartFactory(OFC ofc) {
    super(ofc);
  }

  @Override
  public Chart createChart() {
    Chart chart = super.createChart();
    chart.setXAxis(createXAxis());
    chart.setYAxis(createYAxis());
    return chart;
  }

  /**
   * Generates the element to insert in the Chart
   *
   * @param ofc
   *            Chart object
   * @param s
   *            the serie number
   * @param model
   *
   * @return the generated element
   */
  @Override
  protected List<Element> createElements(OFC ofc, CategoryModel model) {
    int s = model.getSeries().size();
    List<Element> elements = new ArrayList<Element>();
    for(int i=0;i<s;i++) {
      elements.add(createBar(ofc, i));
    }
    return elements;
  }



  @SuppressWarnings("unchecked")
  protected Element createBar(OFC ofc, int s) {
    FilledBarChart e = new FilledBarChart();

    // TODO Create the property OutlineColour
    e.setOutlineColour("#577261");
    if (ofc.getPallete() != null) {
      e.setColour(ofc.getPallete()[s]);
    } else {
      e.setColour("#E2D66A");
    }
    Comparable serie = model.getSeries(s);
    e.setText((String) serie);
    List<Number> values = new ArrayList<Number>();
    for (Iterator itCategories = model.getCategories().iterator(); itCategories
        .hasNext();) {
      Comparable category = (Comparable) itCategories.next();
      Number n = model.getValue(serie, category);
      if (n.doubleValue() < minValue) {
        minValue = n.doubleValue();
      }
      if (n.doubleValue() > maxValue) {
        maxValue = n.doubleValue();
      }
      values.add(n);
    }
    e.addValues(values);
    return e;
  }

  /**
   * Create the X axis of the bar Chart
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  private XAxis createXAxis() {
    XAxis xaxis = new XAxis();
    List<Label> labels = new ArrayList<Label>();
    for (Iterator it = model.getCategories().iterator(); it.hasNext();) {
      Label l = new Label((String) it.next());
      labels.add(l);
    }
    xaxis.addLabels(labels);
    return xaxis;
  }

  /**
   * Create the X axis of the bar Chart
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  private YAxis createYAxis() {
    YAxis yaxis = new YAxis();
    yaxis.setMin(getYMinValue());
    yaxis.setMax(getYMaxValue());
    return yaxis;
  }

}
TOP

Related Classes of ofc.OFCBarChartFactory

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.