示例#1
0
 void refreshLayoutComposite() {
   super.refreshLayoutComposite();
   chart = new Chart(layoutComposite, SWT.NONE);
   chart.getTitle().setText("Hop count");
   chart.getAxisSet().getXAxis(0).getTitle().setText("Time(s)");
   chart.getAxisSet().getYAxis(0).getTitle().setText("Hop count");
   // create line series
   ILineSeries lineSeries =
       (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
   lineSeries.setYSeries(ySeries);
   lineSeries.setXSeries(xSeries);
   lineSeries.setLineStyle(LineStyle.DOT);
   // adjust the axis range
   chart.getAxisSet().adjustRange();
 }
 /**
  * Creates a series
  *
  * @param seriesSet
  * @param data
  * @param label
  * @param symbol
  * @param color
  */
 private void createSeries(
     ISeriesSet seriesSet, double[] data, String label, PlotSymbolType symbol, Color color) {
   ILineSeries series =
       (ILineSeries) seriesSet.createSeries(SeriesType.LINE, label); // $NON-NLS-1$
   series.setAntialias(SWT.ON);
   series.getLabel().setVisible(false);
   series.getLabel().setFont(chart.getFont());
   series.setYSeries(data);
   series.setSymbolType(symbol);
   series.setSymbolColor(color);
   series.setLineColor(color);
   series.setXAxisId(0);
   series.setYAxisId(0);
 }
示例#3
0
  /**
   * create the chart.
   *
   * @param parent The parent composite
   * @return The created chart
   */
  public static Chart createChart(Composite parent) {

    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);

    // set titles
    chart.getTitle().setText("Step Chart");
    chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
    chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

    // create line series
    ILineSeries lineSeries =
        (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
    lineSeries.setYSeries(ySeries);
    lineSeries.setSymbolType(PlotSymbolType.NONE);
    lineSeries.enableStep(true);

    // adjust the axis range
    chart.getAxisSet().adjustRange();

    return chart;
  }
示例#4
0
  private void showData(List<IStoreItem> res) {
    Iterator<IStoreItem> iter = res.iterator();

    // clear the graph
    ISeries[] coll = chart.getSeriesSet().getSeries();
    for (int i = 0; i < coll.length; i++) {
      ISeries iSeries = coll[i];
      chart.getSeriesSet().deleteSeries(iSeries.getId());
    }

    while (iter.hasNext()) {
      ICollection iCollection = (ICollection) iter.next();
      TimeFrequencyBins.BinnedData bins = null;
      if (iCollection.isTemporal()) {
        if (iCollection.size() > 1) {
          if (iCollection.size() <= MAX_SIZE) {
            IBaseTemporalCollection thisQ = (IBaseTemporalCollection) iCollection;
            bins = TimeFrequencyBins.doBins(iCollection, thisQ);

            String seriesName = iCollection.getName();
            ILineSeries newSeries =
                (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, seriesName);
            newSeries.setSymbolType(PlotSymbolType.NONE);
            newSeries.enableArea(true);
            newSeries.setLineColor(PlottingHelpers.colorFor(seriesName));

            Date[] xData = new Date[bins.size() * 2];
            double[] yData = new double[bins.size() * 2];

            // put the data into series
            int ctr = 0;
            Iterator<Bin> iter2 = bins.iterator();
            while (iter2.hasNext()) {
              Bin bin = (TimeFrequencyBins.Bin) iter2.next();
              xData[ctr] = new Date(bin.lowerVal);
              yData[ctr++] = bin.freqVal;
              xData[ctr] = new Date(bin.upperVal);
              yData[ctr++] = bin.freqVal;
            }

            newSeries.setXDateSeries(xData);
            newSeries.setYSeries(yData);

            newSeries.enableStack(true);
            newSeries.enableArea(true);

            // adjust the axis range
            chart.getAxisSet().adjustRange();
            IAxis xAxis = chart.getAxisSet().getXAxis(0);
            xAxis.enableCategory(false);

            // set the y axis min to be zero
            Range yRange = chart.getAxisSet().getYAxis(0).getRange();
            chart.getAxisSet().getYAxis(0).setRange(new Range(0, yRange.upper));

            chart.redraw();
          }
        }
      }
    }
  }
示例#5
0
  private void updateChart(Security security) {
    ISeries series = chart.getSeriesSet().getSeries(Messages.ColumnQuote);
    if (series != null) chart.getSeriesSet().deleteSeries(Messages.ColumnQuote);
    chart.clearMarkerLines();

    if (security == null || security.getPrices().isEmpty()) {
      chart.getTitle().setText(security == null ? "..." : security.getName()); // $NON-NLS-1$
      chart.redraw();
      return;
    }

    chart.getTitle().setText(security.getName());

    List<SecurityPrice> prices = security.getPrices();

    int index;
    Date[] dates;
    double[] values;

    if (chartPeriod == null) {
      index = 0;
      dates = new Date[prices.size()];
      values = new double[prices.size()];
    } else {
      index =
          Math.abs(
              Collections.binarySearch(
                  prices, new SecurityPrice(chartPeriod, 0), new SecurityPrice.ByDate()));

      if (index >= prices.size()) {
        // no data available
        chart.redraw();
        return;
      }

      dates = new Date[prices.size() - index];
      values = new double[prices.size() - index];
    }

    for (int ii = 0; index < prices.size(); index++, ii++) {
      SecurityPrice p = prices.get(index);
      dates[ii] = p.getTime();
      values[ii] = p.getValue() / Values.Quote.divider();
    }

    ILineSeries lineSeries =
        (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, Messages.ColumnQuote);
    lineSeries.setXDateSeries(dates);
    lineSeries.setLineWidth(2);
    lineSeries.enableArea(true);
    lineSeries.setSymbolType(PlotSymbolType.NONE);
    lineSeries.setYSeries(values);
    lineSeries.setAntialias(SWT.ON);

    chart.getAxisSet().adjustRange();

    for (Portfolio portfolio : getClient().getPortfolios()) {
      for (PortfolioTransaction t : portfolio.getTransactions()) {
        if (t.getSecurity() == security
            && (chartPeriod == null || chartPeriod.before(t.getDate()))) {
          String label = Values.Share.format(t.getShares());
          switch (t.getType()) {
            case BUY:
            case TRANSFER_IN:
            case DELIVERY_INBOUND:
              chart.addMarkerLine(t.getDate(), new RGB(0, 128, 0), label);
              break;
            case SELL:
            case TRANSFER_OUT:
            case DELIVERY_OUTBOUND:
              chart.addMarkerLine(t.getDate(), new RGB(128, 0, 0), "-" + label); // $NON-NLS-1$
              break;
            default:
              throw new UnsupportedOperationException();
          }
        }
      }
    }

    chart.redraw();
  }