/**
   * Creates the histogram chart.
   *
   * @param exampleSet
   * @return
   */
  private JFreeChart createHistogramChart(final ExampleSet exampleSet) {
    JFreeChart chart =
        ChartFactory.createHistogram(
            null,
            null,
            null,
            createHistogramDataset(exampleSet),
            PlotOrientation.VERTICAL,
            false,
            false,
            false);
    AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
    chart.setBackgroundPaint(null);
    chart.setBackgroundImageAlpha(0.0f);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setOutlineVisible(false);
    plot.setRangeZeroBaselineVisible(false);
    plot.setDomainZeroBaselineVisible(false);
    plot.getDomainAxis().setTickLabelsVisible(false);
    plot.setBackgroundPaint(COLOR_INVISIBLE);
    plot.setBackgroundImageAlpha(0.0f);

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    return chart;
  }
コード例 #2
0
  /**
   * Paints a single bar instance.
   *
   * @param g2 the graphics target.
   * @param renderer the renderer.
   * @param row the row index.
   * @param column the column index.
   * @param bar the bar
   * @param base indicates which side of the rectangle is the base of the bar.
   * @param pegShadow peg the shadow to the base of the bar?
   */
  public void paintBarShadow(
      Graphics2D g2,
      XYBarRenderer renderer,
      int row,
      int column,
      RectangularShape bar,
      RectangleEdge base,
      boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
      Color c = (Color) itemPaint;
      if (c.getAlpha() == 0) {
        return;
      }
    }

    RectangularShape shadow =
        createShadow(
            bar, renderer.getShadowXOffset(), renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);
  }
 private JFreeChart createChart(IntervalXYDataset intervalxydataset) {
   JFreeChart jfreechart =
       ChartFactory.createXYBarChart(
           frameTitle,
           X_LABEL,
           true,
           Y_LABEL,
           intervalxydataset,
           PlotOrientation.VERTICAL,
           true,
           false,
           false);
   jfreechart.addSubtitle(new TextTitle(SUB_TITLE, new Font("Dialog", 2, 10)));
   jfreechart.setBackgroundPaint(Color.white);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
   StandardXYToolTipGenerator standardxytooltipgenerator =
       new StandardXYToolTipGenerator(
           "{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
   xybarrenderer.setBaseToolTipGenerator(standardxytooltipgenerator);
   xybarrenderer.setMargin(0.10000000000000001D);
   xyplot.setBackgroundPaint(Color.lightGray);
   xyplot.setRangeGridlinePaint(Color.white);
   DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
   dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
   dateaxis.setLowerMargin(0.01D);
   dateaxis.setUpperMargin(0.01D);
   return jfreechart;
 }
コード例 #4
0
 private static JFreeChart createChart() {
   DateAxis dateaxis = new DateAxis("Date");
   dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
   NumberAxis numberaxis = new NumberAxis("Value");
   IntervalXYDataset intervalxydataset = createDataset1();
   XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D);
   xybarrenderer.setBaseToolTipGenerator(
       new StandardXYToolTipGenerator(
           "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
   XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, numberaxis, xybarrenderer);
   NumberAxis numberaxis1 = new NumberAxis("Value 2");
   xyplot.setRangeAxis(1, numberaxis1);
   XYDataset xydataset = createDataset2A();
   StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer();
   standardxyitemrenderer.setBaseToolTipGenerator(
       new StandardXYToolTipGenerator(
           "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
   xyplot.setDataset(1, xydataset);
   xyplot.setRenderer(1, standardxyitemrenderer);
   XYDataset xydataset1 = createDataset2B();
   xyplot.setDataset(2, xydataset1);
   xyplot.setRenderer(2, new StandardXYItemRenderer());
   xyplot.mapDatasetToRangeAxis(2, 1);
   xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
   xyplot.setOrientation(PlotOrientation.VERTICAL);
   JFreeChart jfreechart =
       new JFreeChart("Overlaid XYPlot Demo 2", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
   ChartUtilities.applyCurrentTheme(jfreechart);
   return jfreechart;
 }
コード例 #5
0
ファイル: XYBarRenderer.java プロジェクト: xylo/jfreechart
 /**
  * Returns a clone of the renderer.
  *
  * @return A clone.
  * @throws CloneNotSupportedException if the renderer cannot be cloned.
  */
 @Override
 public Object clone() throws CloneNotSupportedException {
   XYBarRenderer result = (XYBarRenderer) super.clone();
   if (this.gradientPaintTransformer != null) {
     result.gradientPaintTransformer =
         (GradientPaintTransformer) ObjectUtilities.clone(this.gradientPaintTransformer);
   }
   result.legendBar = ShapeUtilities.clone(this.legendBar);
   return result;
 }
コード例 #6
0
  /**
   * @param forecast
   * @param settings (next days)
   * @return
   */
  public JFreeChart createBarChart(
      final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
    Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);
    final LiquidityForecastCashFlow cashFlow =
        new LiquidityForecastCashFlow(forecast, settings.getNextDays());
    final TimeSeries accumulatedSeriesExpected =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.expected"));
    final TimeSeries creditSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.common.credit"));
    final TimeSeries debitSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.common.debit"));
    double accumulatedExpected = settings.getStartAmount().doubleValue();

    final DayHolder dh = new DayHolder();
    final Date lower = dh.getDate();
    for (int i = 0; i < settings.getNextDays(); i++) {
      final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
      if (i > 0) {
        accumulatedExpected +=
            cashFlow.getDebitsExpected()[i - 1].doubleValue()
                + cashFlow.getCreditsExpected()[i - 1].doubleValue();
      }
      accumulatedSeriesExpected.add(day, accumulatedExpected);
      creditSeries.add(day, cashFlow.getCreditsExpected()[i].doubleValue());
      debitSeries.add(day, cashFlow.getDebitsExpected()[i].doubleValue());
      dh.add(Calendar.DATE, 1);
    }
    dh.add(Calendar.DATE, -1);
    final XYChartBuilder cb =
        new XYChartBuilder(
            ChartFactory.createXYBarChart(
                null, null, false, null, null, PlotOrientation.VERTICAL, false, false, false));
    int counter = 0;

    final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
    xyDataSeries.addSeries(accumulatedSeriesExpected);
    final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, true);
    lineRenderer.setSeriesPaint(0, cb.getRedMarker());
    lineRenderer.setSeriesVisibleInLegend(0, true);
    cb.setRenderer(counter, lineRenderer)
        .setDataset(counter++, xyDataSeries)
        .setStrongStyle(lineRenderer, false, accumulatedSeriesExpected);

    final TimeSeriesCollection cashflowSet = new TimeSeriesCollection();
    cashflowSet.addSeries(debitSeries);
    cashflowSet.addSeries(creditSeries);
    final XYBarRenderer barRenderer = new XYBarRenderer(.2);
    barRenderer.setSeriesPaint(0, cb.getGreenFill());
    barRenderer.setSeriesPaint(1, cb.getRedFill());
    barRenderer.setShadowVisible(false);
    cb.setRenderer(counter, barRenderer).setDataset(counter++, cashflowSet);

    cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
    return cb.getChart();
  }
コード例 #7
0
ファイル: ImageHistPanel.java プロジェクト: rforge/timpgui
 private ChartPanel updateHistPanel(double[] data, double minVal, double maxVal, int numPockets) {
   HistogramDataset datasetHist = new HistogramDataset();
   if (numPockets < 1) {
     numPockets = 20;
   }
   datasetHist.addSeries("seria1", data, numPockets, minVal, maxVal);
   JFreeChart charthist =
       ChartFactory.createHistogram(
           null, null, null, datasetHist, PlotOrientation.VERTICAL, false, true, false);
   charthist.setBackgroundPaint(JFreeChart.DEFAULT_BACKGROUND_PAINT);
   XYPlot plot = (XYPlot) charthist.getPlot();
   plot.setForegroundAlpha(0.85f);
   XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
   renderer.setDrawBarOutline(false);
   return new GraphPanel(charthist);
 }
コード例 #8
0
 private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
   JFreeChart jfreechart =
       ChartFactory.createXYBarChart(
           "XYBarChartDemo6",
           "X",
           false,
           "Y",
           intervalxydataset,
           PlotOrientation.HORIZONTAL,
           false,
           false,
           false);
   jfreechart.setBackgroundPaint(Color.white);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
   xybarrenderer.setUseYInterval(true);
   xyplot.setBackgroundPaint(Color.lightGray);
   xyplot.setDomainGridlinePaint(Color.white);
   xyplot.setRangeGridlinePaint(Color.white);
   return jfreechart;
 }
コード例 #9
0
ファイル: Layer.java プロジェクト: ryanmurf/GeoTool
  private JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    String templayerName = layerName;
    if (map.valueSlider.isVisible())
      templayerName = layerName.replace("*", String.valueOf(map.valueSlider.getValue() + 1));

    JFreeChart jfreechart =
        ChartFactory.createHistogram(
            templayerName,
            null,
            null,
            intervalxydataset,
            PlotOrientation.VERTICAL,
            true,
            true,
            false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.85F);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(true);
    return jfreechart;
  }
コード例 #10
0
  private static void configureXYBarRenderer(
      XYBarRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    StandardXYBarPainter barPainter = new StandardXYBarPainter();
    renderer.setBarPainter(barPainter);
    renderer.setGradientPaintTransformer(null);
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
    int seriesCount;
    if (valueSourceData != null) {
      seriesCount = valueSourceData.getSeriesCount();
    } else {
      seriesCount = 0;
    }
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    // don't need shapeDimensionConfig, since the shape can't be represented for bars.

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure series paint if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint());
      }

      // configure general style of the bars
      renderer.setShadowVisible(false);
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
    }
    renderer.setDrawBarOutline(true);
  }
コード例 #11
0
  @Override
  public void initComponents() {
    dataset = new XYSeriesCollection();

    JFreeChart chart =
        ComponentFactory.createXYBarChart(
            K1105_SC.getValue(), K1106_SL.getValue(), dataset, (XYItemLabelGenerator) null);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    final String scLabel = "<html>" + K1105_SC.getValue() + ": ";
    final String slLabel = "<br>" + K1106_SL.getValue() + ": ";

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarAlignmentFactor(0);
    renderer.setMargin(0.2);

    renderer.setSeriesToolTipGenerator(
        0,
        new XYToolTipGenerator() {
          @Override
          public String generateToolTip(XYDataset dataset, int arg1, int arg2) {
            int scNum = (int) dataset.getXValue(arg1, arg2);
            int slCount = (int) dataset.getYValue(arg1, arg2);
            return scLabel + scNum + slLabel + slCount + "</html>";
          }
        });
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(PREFERRED_CHART_SIZE);
    propsPanel.add(chartPanel);
  }
コード例 #12
0
  private static JFreeChart createDistributionViewChart() {
    XYPlot plot = new XYPlot();

    XYLineAndShapeRenderer dRenderer = new XYSplineRenderer();
    dRenderer.setBaseShapesVisible(false);
    dRenderer.setAutoPopulateSeriesPaint(false);
    dRenderer.setAutoPopulateSeriesStroke(false);
    dRenderer.setBaseStroke(TsCharts.getStrongStroke(LinesThickness.Thin));
    dRenderer.setDrawSeriesLineAsPath(true); // not sure if useful
    plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DISTRIBUTION_INDEX, dRenderer);

    XYBarRenderer hRenderer = new XYBarRenderer();
    hRenderer.setShadowVisible(false);
    hRenderer.setDrawBarOutline(true);
    hRenderer.setAutoPopulateSeriesPaint(false);
    hRenderer.setAutoPopulateSeriesOutlinePaint(false);
    hRenderer.setBaseSeriesVisibleInLegend(false);
    plot.setDataset(HISTOGRAM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(HISTOGRAM_INDEX, hRenderer);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);
    plot.setDomainGridlinesVisible(false);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    rangeAxis.setTickUnit(new NumberTickUnit(0.05));
    rangeAxis.setNumberFormatOverride(new DecimalFormat("0.###"));
    plot.setRangeAxis(rangeAxis);

    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    JFreeChart result = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);
    return result;
  }
コード例 #13
0
  private void createUI() {
    dataset = new XIntervalSeriesCollection();
    chart =
        ChartFactory.createHistogram(
            CHART_TITLE,
            "Values",
            "Frequency in #pixels",
            dataset,
            PlotOrientation.VERTICAL,
            false, // Legend?
            true, // tooltips
            false // url
            );
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setDomainZeroBaselineStroke(new BasicStroke(0.2f));

    final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    renderer.setShadowYOffset(-4.0);
    renderer.setBaseToolTipGenerator(new XYPlotToolTipGenerator());
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setSeriesPaint(0, new Color(0, 0, 200));

    createUI(createChartPanel(chart), createOptionsPanel(), bindingContext);

    isInitialized = true;

    final Binding minBinding = xAxisRangeControl.getBindingContext().getBinding("min");
    final double min = (Double) minBinding.getPropertyValue();
    final Binding maxBinding = xAxisRangeControl.getBindingContext().getBinding("max");
    final double max = (Double) maxBinding.getPropertyValue();
    if (!histogramComputing && min > max) {
      minBinding.setPropertyValue(max);
      maxBinding.setPropertyValue(min);
    }
    updateXAxis();
  }
  public void testHistogram1DAdapter() {

    IHistogram1D histogram = histogramFactory.createHistogram1D("h1d", 100, 0, 100);
    Random random = new Random();
    for (int i = 0; i < 100000; i++) {
      histogram.fill(random.nextInt(100));
    }

    Histogram1DAdapter adapter = new Histogram1DAdapter(histogram);

    // int getSeriesCount()
    int seriesCount = adapter.getSeriesCount();
    System.out.println("seriesCount: " + seriesCount);

    // int getItemCount(int series)
    int itemCount = adapter.getItemCount(VALUES);
    System.out.println("itemCount: " + itemCount);

    // Comparable getSeriesKey(int series)
    Comparable<?> seriesKey = adapter.getSeriesKey(VALUES);
    System.out.println("data series key: " + seriesKey);

    seriesKey = adapter.getSeriesKey(ERRORS);
    System.out.println("error series key: " + seriesKey);

    System.out.println();

    for (int item = 0; item < itemCount; item++) {

      System.out.println("item " + item);

      double x = adapter.getXValue(VALUES, item);
      double xLow = adapter.getStartXValue(VALUES, item);
      double xHigh = adapter.getEndXValue(VALUES, item);

      double y = adapter.getYValue(VALUES, item);
      double yLow = adapter.getStartYValue(VALUES, item);
      double yHigh = adapter.getEndYValue(VALUES, item);

      System.out.format(
          "  bin data (x,xLow,xHigh,y,yLow,yHigh) = %f,%f,%f,%f,%f,%f%n",
          x, xLow, xHigh, y, yLow, yHigh);

      x = adapter.getXValue(ERRORS, item);
      xLow = adapter.getStartXValue(ERRORS, item);
      xHigh = adapter.getEndXValue(ERRORS, item);

      y = adapter.getYValue(ERRORS, item);
      yLow = adapter.getStartYValue(ERRORS, item);
      yHigh = adapter.getEndYValue(ERRORS, item);

      System.out.format(
          "  error data (x,xLow,xHigh,y,yLow,yHigh) = %f,%f,%f,%f,%f,%f%n",
          x, xLow, xHigh, y, yLow, yHigh);

      x = adapter.getXValue(POINTS, item);
      y = adapter.getYValue(POINTS, item);
      System.out.format("  point data (x,y) = %f,%f%n", x, y);
    }
    System.out.println();
    System.out.println();

    System.out.println("printing step data ...");
    itemCount = adapter.getItemCount(STEPS);
    System.out.println("step itemCount: " + itemCount);
    for (int item = 0; item < itemCount; item++) {
      System.out.println("item " + item);
      double x = adapter.getXValue(STEPS, item);
      double y = adapter.getYValue(STEPS, item);
      // double y = adapter.getYValue(STEPS, item);
      System.out.format("  step data (x,y) = %f,%f%n", x, y);
    }

    // Set the axis labels.
    String[] labels = ConverterUtil.getAxisLabels(histogram);
    NumberAxis xAxis = new NumberAxis(labels[0]);
    NumberAxis yAxis = new NumberAxis(labels[1]);

    // Create the plot without any data.
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);

    // Bar chart
    XYDataset barData = new Histogram1DAdapter(histogram);
    XYBarRenderer barRenderer = new XYBarRenderer();
    barRenderer.setSeriesVisible(ERRORS, false);
    barRenderer.setSeriesVisible(POINTS, false);
    barRenderer.setSeriesVisible(STEPS, false);
    // barRenderer.setSeriesVisible(VALUES, false); // DEBUG
    barRenderer.setDrawBarOutline(true);
    plot.setDataset(VALUES, barData);
    plot.setRenderer(VALUES, barRenderer);

    // Errors
    XYDataset errors = new Histogram1DAdapter(histogram);
    XYErrorRenderer errorRenderer = new XYErrorRenderer();
    errorRenderer.setSeriesVisible(VALUES, false);
    errorRenderer.setSeriesVisible(POINTS, false);
    errorRenderer.setSeriesVisible(STEPS, false);
    // errorRenderer.setSeriesVisible(ERRORS, false); // DEBUG
    errorRenderer.setBaseShapesVisible(false);
    errorRenderer.setSeriesPaint(0, Color.black);
    plot.setDataset(ERRORS, errors);
    plot.setRenderer(ERRORS, errorRenderer);

    // Points
    XYDataset points = new Histogram1DAdapter(histogram);
    XYItemRenderer pointRenderer = new XYLineAndShapeRenderer();
    pointRenderer.setSeriesVisible(VALUES, false);
    pointRenderer.setSeriesVisible(ERRORS, false);
    pointRenderer.setSeriesVisible(STEPS, false);
    // pointRenderer.setSeriesVisible(POINTS, false); // DEBUG
    plot.setDataset(POINTS, points);
    plot.setRenderer(POINTS, pointRenderer);

    // Steps
    XYDataset steps = new Histogram1DAdapter(histogram);
    XYItemRenderer stepRenderer = new XYStepRenderer();
    stepRenderer.setSeriesVisible(VALUES, false);
    stepRenderer.setSeriesVisible(ERRORS, false);
    stepRenderer.setSeriesVisible(POINTS, false);
    // stepRenderer.setSeriesVisible(STEPS, false);
    plot.setDataset(STEPS, steps);
    plot.setRenderer(STEPS, stepRenderer);

    // Set proper rendering order.
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // Set style.
    ChartFactory.setChartTheme(new DefaultChartTheme());
    XYBarRenderer.setDefaultShadowsVisible(false);

    // Create the chart.
    JFreeChart chart =
        new JFreeChart(histogram.title(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    // Show the chart in an application frame.
    ChartPanel panel = new ChartPanel(chart);
    ApplicationFrame frame = new ApplicationFrame("Histogram1DAdapterTest");
    frame.setContentPane(panel);
    frame.pack();
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
  }
コード例 #15
0
ファイル: SensorWidget.java プロジェクト: tbk303/wowmon
  public SensorWidget(
      final Composite parent,
      final int style,
      final Measurements<T> totals,
      final Measurements<T>... parts) {
    super(parent, style);

    this.totals = totals;

    setLayout(new GridLayout(1, false));
    setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    TimeTableXYDataset dataset = new TimeTableXYDataset();
    XYBarRenderer renderer = new StackedXYBarRenderer(0.0);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);

    if (parts == null || parts.length == 0) {
      renderer.setSeriesPaint(0, Color.green);
    }

    XYPlot plot = new XYPlot(dataset, new DateAxis("Time"), new NumberAxis("Count"), renderer);

    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);
    plot.getRangeAxis().setLabel(null);
    plot.getDomainAxis().setLabel(null);

    JFreeChart realChart = new JFreeChart(plot);
    realChart.setTitle((String) null);

    chart = new ChartComposite(this, SWT.NONE, realChart, true);
    chart.setLayoutData(new GridData(300, 180));

    final Composite labels = new Composite(this, SWT.NONE);
    labels.setLayout(new GridLayout(5, false));

    final Label totalLabel = new Label(labels, SWT.NONE);
    totalLabel.setText(totals.getName());

    total = new Label(labels, SWT.BOLD);
    final FontData[] fd = total.getFont().getFontData();
    fd[0].setStyle(SWT.BOLD);
    total.setFont(new Font(getDisplay(), fd));
    totalMin = new Label(labels, SWT.NONE);
    totalMax = new Label(labels, SWT.NONE);
    totalAvg = new Label(labels, SWT.NONE);

    if (parts != null && parts.length > 0) {
      for (Measurements<T> part : parts) {
        final Label label = new Label(labels, SWT.NONE);
        label.setText(part.getName());
        final Label valueLabel = new Label(labels, SWT.BOLD);
        valueLabel.setFont(new Font(getDisplay(), fd));
        this.parts.put(
            part.getName(),
            new MeasurementsDisplay<T>(
                part,
                valueLabel,
                new Label(labels, SWT.NONE),
                new Label(labels, SWT.NONE),
                new Label(labels, SWT.NONE)));
      }
    }
  }
コード例 #16
0
  /**
   * Paints a single bar instance.
   *
   * @param g2 the graphics target.
   * @param renderer the renderer.
   * @param row the row index.
   * @param column the column index.
   * @param bar the bar
   * @param base indicates which side of the rectangle is the base of the bar.
   */
  public void paintBar(
      Graphics2D g2,
      XYBarRenderer renderer,
      int row,
      int column,
      RectangularShape bar,
      RectangleEdge base) {

    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0, c1;
    if (itemPaint instanceof Color) {
      c0 = (Color) itemPaint;
      c1 = c0.brighter();
    } else if (itemPaint instanceof GradientPaint) {
      GradientPaint gp = (GradientPaint) itemPaint;
      c0 = gp.getColor1();
      c1 = gp.getColor2();
    } else {
      c0 = Color.blue;
      c1 = Color.blue.brighter();
    }

    // as a special case, if the bar colour has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
      return;
    }

    if (base == RectangleEdge.TOP || base == RectangleEdge.BOTTOM) {
      Rectangle2D[] regions = splitVerticalBar(bar, this.g1, this.g2, this.g3);
      GradientPaint gp =
          new GradientPaint(
              (float) regions[0].getMinX(),
              0.0f,
              c0,
              (float) regions[0].getMaxX(),
              0.0f,
              Color.white);
      g2.setPaint(gp);
      g2.fill(regions[0]);

      gp =
          new GradientPaint(
              (float) regions[1].getMinX(),
              0.0f,
              Color.white,
              (float) regions[1].getMaxX(),
              0.0f,
              c0);
      g2.setPaint(gp);
      g2.fill(regions[1]);

      gp =
          new GradientPaint(
              (float) regions[2].getMinX(), 0.0f, c0, (float) regions[2].getMaxX(), 0.0f, c1);
      g2.setPaint(gp);
      g2.fill(regions[2]);

      gp =
          new GradientPaint(
              (float) regions[3].getMinX(), 0.0f, c1, (float) regions[3].getMaxX(), 0.0f, c0);
      g2.setPaint(gp);
      g2.fill(regions[3]);
    } else if (base == RectangleEdge.LEFT || base == RectangleEdge.RIGHT) {
      Rectangle2D[] regions = splitHorizontalBar(bar, this.g1, this.g2, this.g3);
      GradientPaint gp =
          new GradientPaint(
              0.0f,
              (float) regions[0].getMinY(),
              c0,
              0.0f,
              (float) regions[0].getMaxX(),
              Color.white);
      g2.setPaint(gp);
      g2.fill(regions[0]);

      gp =
          new GradientPaint(
              0.0f,
              (float) regions[1].getMinY(),
              Color.white,
              0.0f,
              (float) regions[1].getMaxY(),
              c0);
      g2.setPaint(gp);
      g2.fill(regions[1]);

      gp =
          new GradientPaint(
              0.0f, (float) regions[2].getMinY(), c0, 0.0f, (float) regions[2].getMaxY(), c1);
      g2.setPaint(gp);
      g2.fill(regions[2]);

      gp =
          new GradientPaint(
              0.0f, (float) regions[3].getMinY(), c1, 0.0f, (float) regions[3].getMaxY(), c0);
      g2.setPaint(gp);
      g2.fill(regions[3]);
    }

    // draw the outline...
    if (renderer.isDrawBarOutline()
    /*&& state.getBarWidth() > renderer.BAR_OUTLINE_WIDTH_THRESHOLD*/ ) {
      Stroke stroke = renderer.getItemOutlineStroke(row, column);

      Paint paint = renderer.getItemPaint(row, column);
      if (stroke != null && paint != null) {
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(bar);
      }
    }
  }
コード例 #17
0
  public static JFreeChart createChartZhu(IntervalXYDataset dataset) {

    JFreeChart chart =
        ChartFactory.createXYBarChart(
            "时间段内车辆出入统计柱形图", // title
            "数据日期从" + min + "到" + max,
            true, // x-axis label
            "车辆出入数量", // y-axis label
            dataset,
            PlotOrientation.VERTICAL, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("宋体", Font.BOLD, 15));
    // chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    XYPlot plot2 = (XYPlot) chart.getPlot();
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);
    plot2.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // 设定坐标轴与图表数据显示部分距离
    plot2.setDomainCrosshairVisible(true);
    plot2.setRangeCrosshairVisible(true);
    plot2.getRangeAxis().setLabelFont(new Font("宋体", Font.BOLD, 15));
    // 横轴框里的标题字体
    chart.getLegend().setItemFont(new Font("宋体", Font.ITALIC, 10));
    // 横轴列表字体
    plot2.getDomainAxis().setTickLabelFont(new Font("新宋体", 1, 10));
    // 横轴小标题字体
    plot2.getDomainAxis().setLabelFont(new Font("新宋体", 1, 10));
    plot2.setNoDataMessage("没有数据");
    plot2.setBackgroundAlpha(0.5f);

    XYBarRenderer xyBarRender = new XYBarRenderer();
    xyBarRender.setMargin(0.5); // 设置柱形图之间的间隔

    GradientPaint gradientpaint1 =
        new GradientPaint(0.0F, 0.0F, Color.black, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint3 =
        new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));

    xyBarRender.setSeriesPaint(0, gradientpaint1);
    xyBarRender.setSeriesPaint(1, gradientpaint3);
    xyBarRender.setSeriesVisibleInLegend(1, true, true);
    xyBarRender.setBarAlignmentFactor(0.5);
    xyBarRender.setDrawBarOutline(false);

    xyBarRender.setSeriesStroke(
        0,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {10.0f, 6.0f},
            0.0f));
    xyBarRender.setSeriesStroke(
        1,
        new BasicStroke(
            5.0f,
            BasicStroke.CAP_SQUARE,
            BasicStroke.JOIN_ROUND,
            5.0f,
            new float[] {15.0f, 10.0f},
            10.0f));

    plot2.setRenderer(xyBarRender);
    ClusteredXYBarRenderer clusteredxybarrenderer = new ClusteredXYBarRenderer(0.001D, false);
    plot2.setRenderer(clusteredxybarrenderer);

    // CategoryAxis横抽,通过getDomainAxis取得,NumberAxis纵轴,通过getRangeAxis取得。
    DateAxis axis = (DateAxis) plot2.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
    if (type == 0) // type = 0则以1天为横轴最小坐标,为1则以1月为横轴最小坐标
    {
      axis.setDateFormatOverride(new SimpleDateFormat("dd")); // 设置时间格式
      axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
    } else {
      axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM"));
      axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1));
    }
    axis.setLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
    // axis.setLabelAngle(0.85);
    axis.setAutoTickUnitSelection(false); // 时间轴的数据标签是否自动确
    // ItemLabelPosition itemlabelposition = new
    // ItemLabelPosition(ItemLabelAnchor.INSIDE12,TextAnchor.CENTER_RIGHT,TextAnchor.CENTER_RIGHT,
    // -1.57D);

    // 下面这一块是用来设置轴的时间间隔的,可能会出现,出错时可以简单设处日期就行了
    // 设置X轴间隔的另一种方法更好不出错
    int a = 1;
    a = (int) (daycount / 10) + 1;
    // axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY,a));
    // axis.setLabelAngle(0.45);
    // axis.setLabelInsets(, true);

    NumberAxis numberaxis = (NumberAxis) plot2.getRangeAxis();
    numberaxis.setAxisLineVisible(false); // 是否显示纵坐标
    numberaxis.setTickMarksVisible(false); // 是否显示坐标标尺
    numberaxis.setAutoRangeIncludesZero(false); // 是否自动包含0起点? 默认为true
    numberaxis.setAutoTickUnitSelection(false); // 数据轴的数据标签是否自动确定
    int space_y = (int) ((highValue_Y * 1.1 - minValue_Y * 0.9) / 10);
    if (space_y == 0) space_y = 1;
    System.out.println("spacespace sapce space" + space_y);
    numberaxis.setTickUnit(new NumberTickUnit(space_y)); // 设置刻度显示的密度
    numberaxis.setAutoRangeMinimumSize(2D);
    return chart;
  }
コード例 #18
0
  /**
   * Creates an overlaid chart.
   *
   * @return The chart.
   */
  private static JFreeChart createCombinedChart() {

    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new SimpleDateFormat("d-MMM-yyyy"),
            new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(
        0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 =
        new XYBarRenderer() {
          public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
              return Color.red;
            } else {
              return Color.green;
            }
          }
        };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new SimpleDateFormat("d-MMM-yyyy"),
            new DecimalFormat("0.00")));

    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);
    cplot.setDomainPannable(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart =
        new JFreeChart("United States Public Debt", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    TextTitle source =
        new TextTitle(
            "Source: http://www.publicdebt.treas.gov/opd/opdhisms.htm",
            new Font("Dialog", Font.PLAIN, 10));
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    ChartUtilities.applyCurrentTheme(chart);
    renderer2.setBarPainter(new StandardXYBarPainter());
    renderer2.setShadowVisible(false);
    return chart;
  }