/**
   * 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;
  }
  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);
  }
  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();
  }
  /**
   * 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;
  }
Exemple #5
0
  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)));
      }
    }
  }