/*
   * (non-Javadoc)
   *
   * @see com.ibm.examples.chart.widget.AbstractChartBuilder#buildYSeries()
   */
  protected void buildYSeries() {
    try {

      int starting = 0;
      if (data.length > xSeriesTicks) starting = data.length - xSeriesTicks;
      int yseriescount = adapter.getSeriesCount();
      NumberDataSet orthoValuesDataSet[] = new NumberDataSet[yseriescount];
      ScatterSeries ss1[] = new ScatterSeries[yseriescount];
      SeriesDefinition sdY[] = new SeriesDefinition[yseriescount];

      for (int i = 1; i <= yseriescount; i++) {
        y = new Double[data.length - starting];
        for (int j = starting, k = 0; j < data.length; j++, k++) {
          y[k] = NumberType.obj2num(data[j][i]).doubleValue();
          if (max < y[k]) max = y[k];
          if (min > y[k]) min = y[k];
        }
        orthoValuesDataSet[i - 1] = NumberDataSetImpl.create(y);
        ss1[i - 1] = (ScatterSeries) ScatterSeriesImpl.create();
        ss1[i - 1].setDataSet(orthoValuesDataSet[i - 1]);
        // bs1[i-1].getDisplayName().
        // bs1[i-1].getLabel().setVisible(true);
        // bs1[i-1].setLabelPosition(Position.INSIDE_LITERAL);

        ss1[i - 1].setSeriesIdentifier(labels[i]);
        ss1[i - 1].getMarker().setSize(2);
        // ss1[i-1].getMarkers().
        for (int m = 0; m < ss1[i - 1].getMarkers().size(); m++) {
          ((Marker) ss1[i - 1].getMarkers().get(m)).setType(MarkerType.get(i));
          ((Marker) ss1[i - 1].getMarkers().get(m)).setSize(2);
        }
        // ss1[i-1].getLineAttributes().setVisible(true);
        sdY[i - 1] = SeriesDefinitionImpl.create();
        sdY[i - 1].getSeriesPalette().update(0 - i - 2);

        yAxis.getSeriesDefinitions().add(sdY[i - 1]);
        sdY[i - 1].getSeries().add(ss1[i - 1]);
      }
      System.out.println("not bin updatedataset:" + max);
      yAxis.getScale().setStep(max / 2);
      yAxis.getScale().setMax(NumberDataElementImpl.create(max));

    } catch (Exception e) {
      //   e.printStackTrace();
    }
  }
示例#2
0
  /**
   * Creates a scatter chart model as a reference implementation
   *
   * @return An instance of the simulated runtime chart model (containing filled datasets)
   */
  public static final Chart createDateTimeScatter() {
    ChartWithAxes cwaScatter = ChartWithAxesImpl.create();

    // TODO: research running script under plugin test.

    cwaScatter.setScript(
        "function beforeDrawAxisLabel(axis, label, context)" //$NON-NLS-1$
            + "{label.getCaption().setValue(\"ABC\"); " //$NON-NLS-1$
            + "axis.setLabel(label);}" //$NON-NLS-1$
        );

    // Plot

    cwaScatter.getPlot().getClientArea().getOutline().setVisible(true);

    // Title
    cwaScatter.getTitle().setVisible(false);

    // X-Axis
    Axis xAxisPrimary = ((ChartWithAxesImpl) cwaScatter).getPrimaryBaseAxes()[0];
    xAxisPrimary.getTitle().getCaption().setValue("Time");
    xAxisPrimary.setType(AxisType.DATE_TIME_LITERAL);
    xAxisPrimary.getTitle().setVisible(true);
    xAxisPrimary.getOrigin().setType(IntersectionType.MIN_LITERAL);

    // Y-Axis
    Axis yAxisPrimary = ((ChartWithAxesImpl) cwaScatter).getPrimaryOrthogonalAxis(xAxisPrimary);
    yAxisPrimary.getTitle().getCaption().setValue("Score");

    yAxisPrimary.getTitle().setBackground(ColorDefinitionImpl.WHITE());
    yAxisPrimary.getTitle().setVisible(true);
    yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
    yAxisPrimary.getOrigin().setType(IntersectionType.MIN_LITERAL);

    // create chart data
    int seriesLen = 10;
    double[] yseries = new double[seriesLen];
    Calendar[] datetime = new Calendar[seriesLen];
    for (int i = 0; i < seriesLen; i++) {
      yseries[i] = ((double) i);
      datetime[i] = new GregorianCalendar();
      datetime[i].setTime(new Date(i));
      // uncomment the following line and chart works ok
      // datetime[i].setTime(new Date(i*1000));
    }
    NumberDataSet dsNumericValues2 = NumberDataSetImpl.create(yseries);
    DateTimeDataSet dsDateTime = DateTimeDataSetImpl.create(datetime);

    // X-Series
    Series seBase = SeriesImpl.create();
    seBase.setDataSet(dsDateTime);
    SeriesDefinition sdX = SeriesDefinitionImpl.create();
    xAxisPrimary.getSeriesDefinitions().add(sdX);
    sdX.getSeries().add(seBase);

    // Y-Series
    ScatterSeries ss = (ScatterSeries) ScatterSeriesImpl.create();
    ss.setDataSet(dsNumericValues2);
    SeriesDefinition sdY = SeriesDefinitionImpl.create();
    yAxisPrimary.getSeriesDefinitions().add(sdY);
    sdY.getSeries().add(ss);

    return cwaScatter;
  }