private void update() { UIRegistry.loadAndPushResourceBundle("specify_plugins"); HistogramDataset dataSet = new HistogramDataset(); double max = resultSet.getMax(); dataSet.addSeries( getResourceString("SGR_HISTO_DATASERIES"), resultSet.getValues(1.0), 40, 0.0, max); JFreeChart chart = ChartFactory.createHistogram( getResourceString("SGR_HISTO_TITLE"), getResourceString("SGR_HISTO_X_AXIS"), getResourceString("SGR_HISTO_Y_AXIS"), dataSet, PlotOrientation.VERTICAL, false, // include legend true, // tooltips? false // URLs? ); UIRegistry.popResourceBundle(); XYPlot plot = chart.getXYPlot(); CustomRenderer.setDefaultBarPainter(new StandardXYBarPainter()); CustomRenderer renderer = new CustomRenderer(dataSet); plot.setRenderer(renderer); renderer.setMargin(0.1); ChartPanel chartPanel = new ChartPanel(chart, true, true, true, true, true); removeAll(); add(chartPanel); validate(); }
/** * Creates a chart. * * @param dataset a dataset. * @return The chart. */ private JFreeChart createChart(final IntervalXYDataset dataset) { final JFreeChart chart = ChartFactory.createHistogram( "Histogram Demo", null, null, dataset, PlotOrientation.VERTICAL, true, false, false); chart.getXYPlot().setForegroundAlpha(0.75f); return chart; }
/** * 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; }
public static void generateHistogram( String fileName, double[] value, int numberOfBins, String title, String xLabel, String yLabel) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(title, value, numberOfBins); String plotTitle = title; String xaxis = xLabel; String yaxis = yLabel; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls); int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height); } catch (IOException e) { } }
/** Create the chart */ private void createChart() { if (chartPanel != null) { return; } MyHistogramDataset dataset = new MyHistogramDataset(); chart = ChartFactory.createHistogram( "Histogram", null, null, dataset, PlotOrientation.VERTICAL, true, false, false); chart.getXYPlot().setForegroundAlpha(0.75f); plot = (XYPlot) chart.getPlot(); initXYPlot(plot); chartPanel = doMakeChartPanel(chart); }
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); }
private JFreeChart getTraveledXYsHistogram(final int numberOfBins) { String title = this.xy + " distribution by mode"; String xLabel = "distance (m)"; if (this.xy.equals("times")) { xLabel = "time (s)"; } String yLabel = "number of trips"; boolean legend = true; boolean tooltips = false; boolean urls = false; HistogramDataset data = this.getHistogramDataset(numberOfBins); JFreeChart chart = ChartFactory.createHistogram( title, xLabel, yLabel, data, PlotOrientation.VERTICAL, legend, tooltips, urls); return chart; }
public static void generateChart(double values[], String label) { HistogramDataset dataset = new HistogramDataset(); XYSeries serie = new XYSeries("Gaussian distributuin", true, false); dataset.addSeries("Histogram", values, values.length); if (chart == null) chart = ChartFactory.createHistogram( label, "", "Random values", dataset, PlotOrientation.VERTICAL, true, true, true); XYPlot plot = chart.getXYPlot(); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); // xAxis.setTickUnit(new NumberTickUnit(1)); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); // xAxis.setTickUnit(new NumberTickUnit(0.1)); xAxis.setAutoRangeMinimumSize(10); if (frame == null) frame = new ChartFrame("Allocation", chart); frame.pack(); frame.setVisible(true); }
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; }
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(); }
private void displayRulesLengthHistogram() { // cleanup all the content // this.removeAll(); validate(); repaint(); // construct the dataset // // [1.0] extract all the rules ArrayList<Integer> allRules = new ArrayList<Integer>(); for (GrammarRuleRecord r : chartData.getGrammarRules()) { if (0 == r.ruleNumber()) { continue; } for (RuleInterval interval : r.getRuleIntervals()) { allRules.add(interval.getLength()); } } // [2.0] make data Collections.sort(allRules); // final int minLength = allRules.get(0); final int maxLength = allRules.get(allRules.size() - 1); final int numberOfBins = maxLength / this.chartData.getSAXWindowSize() + 1; double[] values = new double[allRules.size()]; for (int i = 0; i < allRules.size(); i++) { values[i] = allRules.get(i).doubleValue(); } HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries( "Frequencies", values, numberOfBins, 0, numberOfBins * this.chartData.getSAXWindowSize()); String plotTitle = "Rules Length Histogram"; String xaxis = "Rule length"; String yaxis = "Counts"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = false; boolean urls = false; this.chart = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls); this.chart.removeLegend(); NumberAxis myAxis = new NumberAxis(this.chart.getXYPlot().getDomainAxis().getLabel()) { private static final long serialVersionUID = 5839368758428973857L; @Override public List<NumberTick> refreshTicks( Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { // List<NumberTick> allTicks = super.refreshTicks(g2, state, dataArea, edge); List<NumberTick> myTicks = new ArrayList<NumberTick>(); for (int i = 0; i < numberOfBins; i++) { myTicks.add( new NumberTick( TickType.MAJOR, i * chartData.getSAXWindowSize(), String.valueOf(i * chartData.getSAXWindowSize()), TextAnchor.CENTER, TextAnchor.CENTER, 0.0d)); // textAnchor, rotationAnchor, angle)); } // for (Object tick : allTicks) { // NumberTick numberTick = (NumberTick) tick; // // if (TickType.MAJOR.equals(numberTick.getTickType()) // && (numberTick.getValue() % chartData.getSAXWindowSize() != 0)) { // // myTicks.add(new NumberTick(TickType.MINOR, numberTick.getValue(), "", numberTick // // .getTextAnchor(), numberTick.getRotationAnchor(), numberTick.getAngle())); // continue; // } // myTicks.add(tick); // } return myTicks; } }; this.chart.getXYPlot().setDomainAxis(myAxis); ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setMinimumDrawWidth(0); chartPanel.setMinimumDrawHeight(0); chartPanel.setMaximumDrawWidth(1920); chartPanel.setMaximumDrawHeight(1200); // cleanup all the content // this.removeAll(); // put the chart on show // this.add(chartPanel); validate(); repaint(); }