Package ofc

Source Code of ofc.OFCLineChartFactory

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.elements.Element;
import jofc2.model.elements.LineChart;
import jofc2.model.elements.LineChart.Dot;

import org.zkoss.zul.CategoryModel;

public class OFCLineChartFactory extends OFCChartFactory {

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

  public Chart createChart() {
    chart = super.createChart();
    chart.setXAxis(createXAxis());
    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(createLine(ofc, i));
    }
    return elements;
  }

  /**
   * Generates the element to insert in the Chart
   *
   * @param ofc
   *            Chart object
   * @param s
   *            the serie number
   * @param model
   *
   * @return the generated element
   */
  @SuppressWarnings("unchecked")
  private Element createLine(OFC ofc, int s) {
    LineChart e = new LineChart();

    if (ofc.getPallete() != null) {
      e.setColour(ofc.getPallete()[s]);
    } else {
      e.setColour("#E2D66A");
    }
    Comparable serie = model.getSeries(s);
    e.setText((String) serie);
    List<Dot> values = new ArrayList<Dot>();
    for (Iterator itCategories = model.getCategories().iterator(); itCategories
        .hasNext();) {
      Comparable category = (Comparable) itCategories.next();
      Number value = model.getValue(serie, category);
      Dot d = new Dot(value);
      d.setDotSize(1);
      values.add(d);
    }
    e.addDots(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;
  }

}
TOP

Related Classes of ofc.OFCLineChartFactory

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.