示例#1
0
  /**
   * Get the XYSeriesRenderer
   *
   * @param color
   * @param style
   * @return
   */
  protected XYSeriesRenderer getXYSeriesRenderer(int color, PointStyle style) {
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    renderer.setColor(color);
    renderer.setPointStyle(style);
    renderer.setFillPoints(true);
    renderer.setLineWidth(8f);

    return renderer;
  }
示例#2
0
  /**
   * Builds a bar multiple series renderer to use the provided colors.
   *
   * @param colors the series renderers colors
   * @return the bar multiple series renderer
   */
  protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors) {
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setAxisTitleTextSize(25);
    renderer.setChartTitleTextSize(25);
    renderer.setLabelsTextSize(25);
    renderer.setLegendTextSize(25);

    renderer.setBackgroundColor(ColorUtil.BLACK);
    renderer.setApplyBackgroundColor(true);

    int length = colors.length;

    for (int i = 0; i < length; i++) {
      XYSeriesRenderer r = new XYSeriesRenderer();
      r.setColor(colors[i]);
      renderer.addSeriesRenderer(r);
    }

    return renderer;
  }
  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;
  }