/** Makes the chart show category labels or not. */
 private void updateCategories() {
   if (chart != null) {
     IAxisSet axisSet = chart.getAxisSet();
     if (axisSet != null) {
       IAxis xAxis = axisSet.getXAxis(0);
       if (xAxis != null) {
         String[] series = xAxis.getCategorySeries();
         if (series != null) {
           boolean enoughSpace =
               chart.getPlotArea().getSize().x / series.length >= MIN_CATEGORY_WIDTH;
           xAxis.enableCategory(enoughSpace);
           xAxis.getTick().setVisible(enoughSpace);
         }
       }
     }
   }
 }
Пример #2
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();
          }
        }
      }
    }
  }