Пример #1
0
  /** Do the initial setup for the Chart */
  private void init() {
    // #style lineChart
    chart = new LineChart("");
    chart.setUseDefaultColor(false);

    chart.setFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    chart.setDrawAxis(true);
    chart.setPreferredSize(240, 200);
    chart.setMargins(5, 3, 30, 35);
    chart.makeShadowVisible(true);
    chart.setShadowColor(20, 20, 20);
    chart.setColor(0, 0, 0);
    chart.resetData();

    // chart.setMaxYScaleFactor(100);
    // chart.setMaxXScaleFactor(18);
    wec.init();
  }
Пример #2
0
 /*
  * (non-Javadoc)
  * @see org.javarosa.formmanager.view.chatterbox.widget.ExpandedWidget#updateWidget(org.javarosa.core.model.QuestionDef)
  */
 protected void updateWidget(FormEntryPrompt prompt) {
   currentTemplate = (IGraphTemplate) templates.get(prompt.getPromptAttributes());
   chart.resetData();
   applyTemplate(data);
   applyData();
 }
Пример #3
0
  /*
   * (non-Javadoc)
   * @see org.javarosa.formmanager.view.chatterbox.widget.ExpandedWidget#setWidgetValue(java.lang.Object)
   */
  protected void setWidgetValue(Object o) {
    if (o instanceof Vector) {
      data = (Vector) o;

      int numPoints = data.size();

      int scaledRes = resolution / numPoints;

      chartXPointsArray = new Integer[numPoints];
      chartYPointsArray = new Integer[numPoints];

      Long minDate = null;
      Long maxDate = null;

      Integer minVal = null;
      Integer maxVal = null;

      Enumeration en = data.elements();
      while (en.hasMoreElements()) {
        DateValueTuple tuple = (DateValueTuple) en.nextElement();
        long time = tuple.date.getTime();
        if (minDate == null || minDate.longValue() > time) {
          minDate = new Long(time);
        }
        if (maxDate == null || maxDate.longValue() < time) {
          maxDate = new Long(time);
        }

        int val = tuple.value;
        if (minVal == null || minVal.intValue() > val) {
          minVal = new Integer(val);
        }
        if (maxVal == null || maxVal.intValue() < val) {
          maxVal = new Integer(val);
        }
      }

      long dateSpan = maxDate.longValue() - minDate.longValue();
      if (dateSpan == 0) {
        dateSpan = 1;
      }
      // int valSpan = maxVal.intValue() - minVal.intValue();

      long dateRes = dateSpan / numPoints;

      // int valRes = valSpan / numPoints;

      Vector xpoints = new Vector();
      Vector ypoints = new Vector();
      en = data.elements();
      while (en.hasMoreElements()) {
        DateValueTuple tuple = (DateValueTuple) en.nextElement();
        long time = tuple.date.getTime();
        long timeUnit = (time - minDate.longValue()) * scaledRes;
        long scaledTime = (timeUnit / dateRes);
        int intScaled = (int) scaledTime;
        int finalTime = intScaled;
        Integer xPoint = new Integer(finalTime);
        Integer val = new Integer(tuple.value);

        xpoints.addElement(xPoint);
        ypoints.addElement(val);
      }
      xpoints.copyInto(chartXPointsArray);
      ypoints.copyInto(chartYPointsArray);

      // chart.setMaxYScaleFactor((maxVal.intValue()*2)/3);
      // chart.setMinYScaleFactor(minVal.intValue());

      chart.resetData();
      applyTemplate(data);
      applyData();
    }
  }