List of usage examples for org.jfree.chart.axis NumberAxis setRange
public void setRange(Range range)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.WinLose.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); DefaultCategoryDataset dataset = (DefaultCategoryDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createBarChart(name, null, null, dataset, PlotOrientation.VERTICAL, legend, false, false);/* w w w .jav a2 s .co m*/ chart.setBorderVisible(false); chart.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(color); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); plot.setRangeCrosshairPaint(color.BLACK); // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setCategoryMargin(0.2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); rangeAxis.setRange(new Range(-(barHeight + 0.2), (barHeight + 0.2))); // customize renderer MyBarRendererThresholdPaint renderer = new MyBarRendererThresholdPaint(useTargets, thresholds, dataset, timeSeries, nullValues, bottomThreshold, color); if (wlt_mode.doubleValue() == 0) { renderer.setBaseItemLabelsVisible(Boolean.FALSE, true); } else { renderer.setBaseItemLabelsVisible(Boolean.TRUE, true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.#")) { public String generateLabel(CategoryDataset dataset, int row, int column) { if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0) return ""; String columnKey = (String) dataset.getColumnKey(column); int separator = columnKey.indexOf('-'); String month = columnKey.substring(0, separator); String year = columnKey.substring(separator + 1); int monthNum = Integer.parseInt(month); if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) { if (wlt_mode.doubleValue() == 2 && column % 2 == 0) return ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, monthNum - 1); SimpleDateFormat dataFormat = new SimpleDateFormat("MMM"); return dataFormat.format(calendar.getTime()); } else return "" + monthNum; } }); } if (wlt_mode.doubleValue() == 3) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2)); } else if (wlt_mode.doubleValue() == 4 || wlt_mode.doubleValue() == 5) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4)); } if (legend == true) { LegendItemCollection collection = createThresholdLegend(plot); plot.setFixedLegendItems(collection); } if (maxBarWidth != null) { renderer.setMaximumBarWidth(maxBarWidth); } //renderer.setSeriesPaint(0, Color.BLUE); plot.setRenderer(renderer); logger.debug("OUT"); if (mainThreshold == null) return null; return chart; }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.BulletGraph.java
public JFreeChart createChart() { logger.debug("IN"); Number value = null;/*w ww . ja va2 s. com*/ if (dataset == null) { logger.debug("The dataset to be represented is null"); value = new Double(0); } else { value = dataset.getValue(); } DefaultCategoryDataset datasetC = new DefaultCategoryDataset(); datasetC.addValue(value, "", ""); // customize a bar chart JFreeChart chart = ChartFactory.createBarChart(null, null, null, datasetC, PlotOrientation.HORIZONTAL, false, false, false); chart.setBorderVisible(false); CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(true); plot.setOutlinePaint(Color.BLACK); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setAnchorValue(value.doubleValue()); // add the target marker if (target != null) { ValueMarker marker = new ValueMarker(target.doubleValue(), Color.BLACK, new BasicStroke(2.0f)); plot.addRangeMarker(marker, Layer.FOREGROUND); } //sets different marks for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); // add the marks IntervalMarker marker = new IntervalMarker(interval.getMin(), interval.getMax(), interval.getColor()); plot.addRangeMarker(marker, Layer.BACKGROUND); logger.debug("Added new interval to the plot"); } // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(show_axis); rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 4)); // calculate the upper limit //double upperBound = target * upperFactor; rangeAxis.setRange(new Range(lower, upper)); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // customize renderer BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(0.18); renderer.setSeriesPaint(0, Color.BLACK); /*BasicStroke d = new BasicStroke(3f,BasicStroke.CAP_ROUND ,BasicStroke.JOIN_ROUND); renderer.setSeriesOutlineStroke(0, d); renderer.setSeriesStroke(0, d); renderer.setStroke(d);*/ return chart; }
From source file:view.FuzzySetView.java
private void setupPlotAxes() { NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); xAxis.setTickUnit(new NumberTickUnit(TICK_UNIT)); yAxis.setTickUnit(new NumberTickUnit(0.2)); Range fuzzySetRange = getFuzzySet().range; xAxis.setRange(fuzzySetRange); yAxis.setRange(0, 1.2);//from ww w.j av a2 s. c o m }
From source file:org.usfirst.frc.team2084.neuralnetwork.HeadingNeuralNetworkTrainer.java
public HeadingNeuralNetworkTrainer() { outputGraphNetworkSeries = new XYSeries("Network Prediction"); outputGraphDataSeries = new XYSeries("Error"); final XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(outputGraphDataSeries); data.addSeries(outputGraphNetworkSeries); outputGraph = ChartFactory.createXYLineChart("Error vs. Output", "Time", "Error", data, PlotOrientation.VERTICAL, true, true, false); NumberAxis xAxis = new NumberAxis(); xAxis.setRange(new Range(-Math.PI, Math.PI)); xAxis.setAutoRange(false);// w w w. j av a 2 s . c o m NumberAxis yAxis = new NumberAxis(); yAxis.setRange(new Range(-1, 1)); XYPlot plot = (XYPlot) outputGraph.getPlot(); plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); network = new Network(new int[] { 1, 5, 1 }, eta, momentum, new TransferFunction.HyperbolicTangent()); try { SwingUtilities.invokeAndWait(() -> { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container content = frame.getContentPane(); content.setLayout(new BorderLayout()); outputGraphPanel = new ChartPanel(outputGraph); outputGraphPanel.setDomainZoomable(false); outputGraphPanel.setRangeZoomable(false); graphPanel.add(outputGraphPanel); graphPanel.setLayout(new GridLayout(1, 1)); content.add(graphPanel, BorderLayout.CENTER); { JLabel etaLabel = new JLabel("Eta:"); etaLabel.setLabelFor(etaField); etaField.setText(Double.toString(network.getEta())); etaField.setColumns(5); etaField.addPropertyChangeListener("value", (evt) -> eta = ((Number) evt.getNewValue()).doubleValue()); controlPanel.add(etaLabel); controlPanel.add(etaField); JLabel momentumLabel = new JLabel("Momentum:"); momentumLabel.setLabelFor(etaField); momentumField.setText(Double.toString(network.getMomentum())); momentumField.setColumns(5); momentumField.addPropertyChangeListener("value", (evt) -> momentum = ((Number) evt.getNewValue()).doubleValue()); controlPanel.add(momentumLabel); controlPanel.add(momentumField); JLabel iterationsLabel = new JLabel("Iterations:"); iterationsLabel.setLabelFor(iterationsField); iterationsField.setText(Integer.toString(iterations)); iterationsField.setColumns(10); iterationsField.addPropertyChangeListener("value", (evt) -> iterations = ((Number) evt.getNewValue()).intValue()); controlPanel.add(iterationsLabel); controlPanel.add(iterationsField); } chooseDataButton.addActionListener((e) -> { if (dataDirectoryChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { dataDirectory = dataDirectoryChooser.getSelectedFile(); displayData(); } }); controlPanel.add(chooseDataButton); trainButton.addActionListener((e) -> trainNetwork()); controlPanel.add(trainButton); saveButton.addActionListener((e) -> { saveNetwork(); }); controlPanel.add(saveButton); content.add(controlPanel, BorderLayout.SOUTH); dataDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }); } catch (InvocationTargetException | InterruptedException e) { e.printStackTrace(); } }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void configureAxis(XYPlot plot) { SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy"); DateAxis dateAxis = new DateAxis(); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateAxis.setDateFormatOverride(sdf); plot.setDomainAxis(dateAxis);/*from w w w . j a v a 2 s .com*/ NumberAxis yaxis = new NumberAxis(); if (range != null) { yaxis.setRange(range); } plot.setRangeAxis(yaxis); }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a snp interval histogram without any axes * @param intervals/*from w w w .j a va 2s . c om*/ * the intervals to use * @param startInBasePairs * where should we start the graph? * @param extentInBasePairs * how far should the graph extend * @param visualInterval * the visual interval to use * @param xAxisLabel * the x axis title to use * @param yAxisLabel * the y axis title to use * @return * the histogram */ public JFreeChart createSnpIntervalHistogram(final List<? extends RealValuedBasePairInterval> intervals, final long startInBasePairs, final long extentInBasePairs, final HighlightedSnpInterval visualInterval, final String xAxisLabel, final String yAxisLabel) { // create the axes NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs)); if (xAxisLabel != null) { xAxis.setLabel(xAxisLabel); } NumberAxis yAxis = new NumberAxis(); if (yAxisLabel != null) { yAxis.setLabel(yAxisLabel); } // create the plot XYPlot plot = this.createSnpIntervalHistogramPlot(intervals, visualInterval, xAxis, yAxis); // create the final chart JFreeChart histogram = new JFreeChart(plot); histogram.removeLegend(); return histogram; }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a snp interval histogram without any axes * @param intervals/*from ww w . ja v a 2 s . co m*/ * the intervals to use * @param startInBasePairs * where should we start the graph? * @param extentInBasePairs * how far should the graph extend * @param visualInterval * the visual interval to use * @return * the histogram */ public JFreeChart createSnpIntervalHistogram(final List<? extends RealValuedBasePairInterval> intervals, final long startInBasePairs, final long extentInBasePairs, final HighlightedSnpInterval visualInterval) { // create the axes NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs)); NumberAxis yAxis = new NumberAxis(); // hide the axes xAxis.setVisible(false); yAxis.setVisible(false); // create the plot XYPlot plot = this.createSnpIntervalHistogramPlot(intervals, visualInterval, xAxis, yAxis); // more hiding plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); // create the final chart JFreeChart histogram = new JFreeChart(plot); histogram.removeLegend(); return histogram; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java
private static JFreeChart createChart(BarGraphDataSeries dataSeries) { if (dataSeries == null) return null; BarGraphDataSeries ds = dataSeries;/* w w w.j a v a 2 s. c o m*/ // create the chart... JFreeChart chart = ChartFactory.createBarChart(ds.getTitle(), // chart title ds.getDomainLabel(), // domain axis label ds.getRangeLabel(), // range axis label ds.getDataSet(0), // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp3); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); ValueRange vr = ds.getRangeValueRanges().get(0); if (vr != null) { Range range = new Range(vr.getMin() / vr.getScale(), vr.getMax() / vr.getScale()); rangeAxis.setRange(range); } return chart; }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a SNP block graph for the given parameters. This graph * will show where the intervals do and don't exist. Interval lists * are organized with the X axis label matching the list's key * @param snpIntervals/*from w w w . j a va 2 s. c o m*/ * the blocks * @param startInBasePairs * the x location to start the graph at * @param extentInBasePairs * the extent to use for the graph * @param maximumImageBlockCount * the max # of separate image blocks to use * @param renderAxes * if true render the axes... otherwise dont * @param legendText * the text to use for the legend * @param yAxisText * the text to use for the y axis * @param trueColor * the color to use for true * @param falseColor * the color to use for false * @return * the graph */ public JFreeChart createSnpIntervalGraph( final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs, final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes, final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) { XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs, maximumImageBlockCount); NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)"); xAxis.setAutoRangeIncludesZero(false); xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs)); String[] sortedStrainNames = extractSortedStrainNames(snpIntervals); for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) { LOG.info("Strain Name: " + sortedStrainNames[strainIndex]); } SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); LegendItemCollection items = new LegendItemCollection(); if (legendText != null) { items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0), trueColor, new BasicStroke(), Color.BLACK)); } plot.setFixedLegendItems(items); XYBlockRenderer r = new XYBlockRenderer(); SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor); r.setPaintScale(ps); r.setBlockHeight(1.0); r.setBlockWidth(1.0); plot.setRenderer(r); final JFreeChart chart; if (renderAxes) { chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { xAxis.setVisible(false); yAxis.setVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); chart = new JFreeChart(plot); } chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java
private JFreeChart createChart() { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label null, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls );/*from w w w. ja v a 2 s .c o m*/ chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false); ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false); } ValueAxis xAxis = plot.getDomainAxis(); if (indexAxis > -1) { xAxis.setLabel(getDataTable().getColumnName(indexAxis)); } else { xAxis.setLabel(SERIESINDEX_LABEL); } xAxis.setAutoRange(true); xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); if (indexAxis > 0) { if (getRangeForDimension(indexAxis) != null) { xAxis.setRange(getRangeForDimension(indexAxis)); } } else { if (getRangeForName(SERIESINDEX_LABEL) != null) { xAxis.setRange(getRangeForName(SERIESINDEX_LABEL)); } } // renderer and range axis synchronized (dataTable) { int numberOfSelectedColumns = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { numberOfSelectedColumns++; } } } int columnCount = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { // YIntervalSeries series = new // YIntervalSeries(this.dataTable.getColumnName(c)); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataTable.getColumnName(c)); Iterator<DataTableRow> i = dataTable.iterator(); int index = 1; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(c); if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { double indexValue = row.getValue(indexAxis); series.add(indexValue, value); } else { series.add(index++, value); } } dataset.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Color color = getColorProvider().getPointColor(1.0d); if (numberOfSelectedColumns > 1) { color = getColorProvider() .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1)); } renderer.setSeriesPaint(0, color); renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesShapesVisible(0, false); NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c)); if (getRangeForDimension(c) != null) { yAxis.setRange(getRangeForDimension(c)); } else { yAxis.setAutoRange(true); yAxis.setAutoRangeStickyZero(false); yAxis.setAutoRangeIncludesZero(false); } yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); if (numberOfSelectedColumns > 1) { yAxis.setAxisLinePaint(color); yAxis.setTickMarkPaint(color); yAxis.setLabelPaint(color); yAxis.setTickLabelPaint(color); } plot.setRangeAxis(columnCount, yAxis); plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT); plot.setDataset(columnCount, dataset); plot.setRenderer(columnCount, renderer); plot.mapDatasetToRangeAxis(columnCount, columnCount); columnCount++; } } } } chart.setBackgroundPaint(Color.white); return chart; }