예제 #1
0
  protected XYMultipleSeriesDataset buildDataset(String[] titles, List<double[]> xyValues) {
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

    XYSeries series = getXYSeries(titles[0], xyValues.get(0), xyValues.get(1));
    dataset.addSeries(series);

    // we may have trend line data as well
    if (titles.length == 2 && xyValues.size() == 3) {
      series = getXYSeries(titles[1], xyValues.get(0), xyValues.get(2));
      dataset.addSeries(series);
    }

    return dataset;
  }
예제 #2
0
 /**
  * Builds a bar multiple series dataset using the provided values.
  *
  * @param titles the series titles
  * @param values the values
  * @return the XY multiple bar dataset
  */
 protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values) {
   XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
   int length = titles.length;
   for (int i = 0; i < length; i++) {
     CategorySeries series = new CategorySeries(titles[i]);
     double[] v = values.get(i);
     int seriesLength = v.length;
     for (int k = 0; k < seriesLength; k++) {
       series.add(v[k]);
     }
     dataset.addSeries(series.toXYSeries());
   }
   return dataset;
 }
예제 #3
0
  public void setRegion(String region) {
    this.currentRegion = region;
    renderer.setChartTitle(region);
    renderer.getSeriesRendererAt(0).setColor(colors[viewMode]);
    ((XYSeriesRenderer) renderer.getSeriesRendererAt(0))
        .setFillBelowLineColor(0x33000000 | colors[viewMode]);
    if (getComponentForm() != null) {

      XYMultiSeriesTransition t = new XYMultiSeriesTransition(chart, dataSet);
      RegionData[] rdArr = data.getRegionData(region);
      for (RegionData rd : rdArr) {
        switch (viewMode) {
          case VIEW_MODE_POPULATION:
            dataSet.getSeriesAt(0).setTitle("Population");
            t.getBuffer().getSeriesAt(POPULATION).add(rd.year, rd.pop);
            break;
          case VIEW_MODE_DENSITY:
            dataSet.getSeriesAt(0).setTitle("Density (People per square mile)");
            t.getBuffer().getSeriesAt(POPULATION).add(rd.year, rd.density);
            break;
          default:
            throw new RuntimeException("Illegal view mode.");
        }

        // t.getBuffer().getSeriesAt(DENSITY).add(rd.year, rd.density);
        // t.getBuffer().getSeriesAt(RANK).add(rd.year, rd.rank);
      }
      t.animateChart();
    } else {
      RegionData[] rdArr = data.getRegionData(region);
      renderer.getSeriesRendererAt(0).setColor(colors[viewMode]);
      for (RegionData rd : rdArr) {

        switch (viewMode) {
          case VIEW_MODE_POPULATION:
            dataSet.getSeriesAt(POPULATION).add(rd.year, rd.pop);
            dataSet.getSeriesAt(0).setTitle("Population");

            break;
          case VIEW_MODE_DENSITY:
            dataSet.getSeriesAt(0).setTitle("Density (People per square mile)");
            dataSet.getSeriesAt(POPULATION).add(rd.year, rd.density);
            break;
          default:
            throw new RuntimeException("Illegal view mode");
        }
      }
      Log.p("Finished adding pop data");
    }
  }
 /**
  * Gets the buffer/cache for values. Values set in the buffer will be applied to the target
  * dataset when the transition takes place.
  *
  * @return
  */
 public XYMultipleSeriesDataset getBuffer() {
   if (datasetCache == null) {
     datasetCache = new XYMultipleSeriesDataset();
     for (int i = 0; i < dataset.getSeriesCount(); i++) {
       datasetCache.addSeries(new XYSeries(dataset.getSeriesAt(i).getTitle()));
     }
     seriesTransitions = new XYSeriesTransition[dataset.getSeries().length];
     for (int i = 0; i < seriesTransitions.length; i++) {
       seriesTransitions[i] = new XYSeriesTransition(getChart(), dataset.getSeriesAt(i));
       seriesTransitions[i].setBuffer(datasetCache.getSeriesAt(i));
     }
   }
   return datasetCache;
 }
예제 #5
0
  public DensityChart(PopulationData data) {

    colors = new int[] {0x660000, 0x006600};
    dataSet = new XYMultipleSeriesDataset();
    XYSeries[] series = new XYSeries[] {new XYSeries("Population")};

    renderer = new XYMultipleSeriesRenderer();
    XYSeriesRenderer[] renderers =
        new XYSeriesRenderer[] {
          new XYSeriesRenderer(),
        };

    for (XYSeriesRenderer r : renderers) {
      r.setLineWidth(2);
      r.setColor(0xffff0000);
      r.setFillBelowLine(true);
      r.setFillBelowLineColor(0x33ff0000);
      renderer.addSeriesRenderer(r);
    }
    renderer.setBackgroundColor(0xff000000);
    renderer.setInitialRange(new double[] {1900, 2010, 0, 800000});
    renderer.setXAxisMin(1910);
    renderer.setMarginsColor(0xffffff);
    renderer.setAxesColor(0x0);
    renderer.setXLabelsColor(0x0);
    renderer.setYLabelsColor(0, 0x0);
    renderer.setShowGridX(true);
    renderer.setGridColor(0xcccccc);

    dataSet.addAllSeries(Arrays.asList(series));

    LineChart lc =
        new LineChart(dataSet, renderer) {

          @Override
          protected ClickableArea[] clickableAreasForPoints(
              List<Float> points,
              List<Double> values,
              float yAxisValue,
              int seriesIndex,
              int startIndex) {
            ClickableArea[] hotspots =
                super.clickableAreasForPoints(points, values, yAxisValue, seriesIndex, startIndex);
            for (ClickableArea area : hotspots) {
              area.getRect().setY(0);
              area.getRect().setHeight(10000);
            }
            return hotspots;
          }
        };

    chart =
        new ChartComponent(lc) {

          @Override
          protected void seriesPressed(SeriesSelection sel) {
            super.seriesPressed(sel);
            yearPressed((int) sel.getXValue());
          }
        };

    this.setLayout(new BorderLayout());
    this.addComponent(BorderLayout.CENTER, chart);
    this.data = data;
  }