Java Code Examples for org.jfree.chart.ChartFactory#createHistogram()

The following examples show how to use org.jfree.chart.ChartFactory#createHistogram() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 2
Source File: BeltDateTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(final Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	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;
}
 
Example 3
Source File: BeltNumericalColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			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.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

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

	return chart;
}
 
Example 4
Source File: BeltTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(final Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	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;
}
 
Example 5
Source File: DateTimeAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: NumericalAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(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.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

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

	return chart;
}
 
Example 7
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 8
Source File: HistogramChartFactory.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 9
Source File: StatisticsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static ChartPanel getHistogramPlotPanel(XIntervalSeriesCollection dataset, String xAxisLabel, String yAxisLabel, Color color) {
        JFreeChart chart = ChartFactory.createHistogram(
                null,
                xAxisLabel,
                yAxisLabel,
                dataset,
                PlotOrientation.VERTICAL,
                false,  // Legend?
                true,   // tooltips
                false   // url
        );
        final XYPlot xyPlot = chart.getXYPlot();
        //xyPlot.setForegroundAlpha(0.85f);
        xyPlot.setNoDataMessage("No data");
        xyPlot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

        final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
        renderer.setDrawBarOutline(false);
        renderer.setShadowVisible(false);
        renderer.setSeriesPaint(0, color);
        StandardXYBarPainter painter = new StandardXYBarPainter();
        renderer.setBarPainter(painter);

        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(300, 200));
//        chartPanel.getPopupMenu().add(createCopyDataToClipboardMenuItem());
        return chartPanel;
    }
 
Example 10
Source File: HistogramPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 11
Source File: HouseholdsPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected JFreeChart createIncomeDistributionPanel(final Currency currency) {
	final IntervalXYDataset dataset = ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.incomeDistributionModel.getHistogramDataset();
	final JFreeChart incomeDistributionChart = ChartFactory.createHistogram("Income Distribution", "Income",
			"% Households at Income", dataset, PlotOrientation.VERTICAL, true, false, false);
	return incomeDistributionChart;
}
 
Example 12
Source File: HistogramChart.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public HistogramChart() {
  super(ChartFactory.createHistogram("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  ));

  // initialize the chart by default time series chart from factory
  chart = getChart();

  // title
  chartTitle = chart.getTitle();
  chartTitle.setFont(titleFont);
  chartTitle.setMargin(5, 0, 0, 0);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // legend constructed by ChartFactory
  LegendTitle legend = chart.getLegend();
  legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  chart.setBackgroundPaint(Color.white);

  // disable maximum size (we don't want scaling)
  // setMaximumDrawWidth(Integer.MAX_VALUE);
  // setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(true);

  // set the logarithmic axis
  NumberAxis axisDomain = new HistogramDomainAxis();
  axisDomain.setMinorTickCount(1);
  axisDomain.setAutoRange(true);

  NumberAxis axisRange = new NumberAxis();
  axisRange.setMinorTickCount(1);
  axisRange.setAutoRange(true);

  plot.setDomainAxis(axisDomain);
  plot.setRangeAxis(axisRange);

  ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
  renderer.setMargin(marginSize);
  renderer.setShadowVisible(false);
  plot.setRenderer(renderer);

  // this.setMinimumSize(new Dimension(400, 400));
  // this.setDismissDelay(Integer.MAX_VALUE);
  // this.setInitialDelay(0);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 13
Source File: AdvancedLtmStatsPanel.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void rebuildPanel(Collection<CardFile> currentFiles) {
        removeAll();

        // setup the stacked bar chart
        dataset = new HistogramDataset();
//        dataset.addSeries("test", new double[]{1,2,3},1);
        final JFreeChart chart = ChartFactory.createHistogram(
                null,  // chart title
                Utils.getRB().getString("CardTableModel.stats.weekSchedule"),                  // domain axis label
//                "# cards",                     // range axis label
                null,                     // range axis label
                dataset,                     // data
                PlotOrientation.VERTICAL,    // the plot orientation
                false,                        // legend
                true,                        // tooltips
                false                        // urls
        );

        add(new ChartPanel(chart), BorderLayout.CENTER);
//        rebuildPanel(new HashSet<CardFile>());

        if (currentFiles != null)
            this.currentFiles = currentFiles;

//        dataset.setGroup(null);

        if (this.currentFiles == null)
            return;

        List<Double> eValues = new ArrayList<Double>();

        for (CardFile currentFile : currentFiles) {
            for (Item item : currentFile.getFlashCards().getLTMItems()) {
                LTMItem ltmItem = (LTMItem) item;
                eValues.add(ltmItem.getEFactor());
            }
        }
        double[] eVals = new double[eValues.size()];
        for (int i = 0; i < eValues.size(); i++) {
            eVals[i] = eValues.get(i);

        }


        if (eVals.length > 0)
            dataset.addSeries("test", eVals, 10);

        HistogramDataset dataset1 = new HistogramDataset();
        dataset1.addSeries("test", eVals, 10);

        repaint();

//        computeScheduleHist(this.currentFiles);
//        set2EDistribution(currentFiles);
    }
 
Example 14
Source File: HistogramChart.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public HistogramChart() {
  super(null, true);

  // initialize the chart by default time series chart from factory
  chart = ChartFactory.createHistogram("", // title
      "", // x-axis label
      "", // y-axis label
      null, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // create legend
      false, // generate tooltips
      false // generate URLs
  );

  // title
  chartTitle = chart.getTitle();
  chartTitle.setFont(titleFont);
  chartTitle.setMargin(5, 0, 0, 0);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // legend constructed by ChartFactory
  LegendTitle legend = chart.getLegend();
  legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(true);

  // set the logarithmic axis
  NumberAxis axisDomain = new HistogramDomainAxis();
  axisDomain.setMinorTickCount(1);
  axisDomain.setAutoRange(true);

  NumberAxis axisRange = new NumberAxis();
  axisRange.setMinorTickCount(1);
  axisRange.setAutoRange(true);

  plot.setDomainAxis(axisDomain);
  plot.setRangeAxis(axisRange);

  ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
  renderer.setMargin(marginSize);
  renderer.setShadowVisible(false);
  plot.setRenderer(renderer);

  this.setMinimumSize(new Dimension(400, 400));
  this.setDismissDelay(Integer.MAX_VALUE);
  this.setInitialDelay(0);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 15
Source File: ScaleBuilder.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void plot (Point upperLeft)
        {
            // All values, quorum line & spread line
            plotValues();
            plotQuorumLine();
            plotSpreadLine("", peak);

            // Second peak spread line?
            if (secondPeak != null) {
                plotSpreadLine("Second", secondPeak);
            }

            // Chart
//            JFreeChart chartLines = ChartFactory.createXYLineChart(
//                    sheet.getId() + " (" + name + " runs)", // Title
//                    "Lengths " + ((scale != null) ? scale : "*no scale*"), // X-Axis label
//                    "Counts", // Y-Axis label
//                    dataset, // Dataset
//                    PlotOrientation.VERTICAL, // orientation,
//                    true, // Show legend
//                    false, // Show tool tips
//                    false // urls
//                    );
            // use a histogram so we can see the actual buckets values
            // rather than being left to interpolate for any given length
	    JFreeChart chart = ChartFactory.createHistogram(
                    sheet.getId() + " (" + name + " runs)", // Title
                    "", // X-Axis label - already labeled in chartLines
                    "", // Y-Axis label - already labeled in chartLines
                    dataset, // Dataset
                    PlotOrientation.VERTICAL, // orientation,
                    true, // Show legend
                    false, // Show tool tips
                    false // urls
                    );
            // have the quorum and spread be lines rather than bars
            XYPlot xyPlot = (XYPlot) chart.getPlot();
            xyPlot.setDataset(1, datasetLines);
            XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer();
            renderer1.setSeriesPaint(0, Color.GREEN); 
            xyPlot.setRenderer(1, renderer1);
            // "FORWARD" causes the added dataset of 
            // lines to be overlayed on histogram bars
            xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
            
            // Hosting frame
            ChartFrame frame = new ChartFrame(
                    sheet.getId() + " - " + name + " runs",
                    chart,
                    true);
            frame.pack();
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            frame.setLocation(upperLeft);
            frame.setVisible(true);
        }