List of usage examples for org.jfree.chart.axis NumberAxis setLabel
public void setLabel(String label)
From source file:loci.slim2.process.interactive.ui.DefaultExcitationGraph.java
/** * Creates the chart/* w w w . j a v a2 s. c o m*/ * * @param bins number of bins * @param timeInc time increment per bin * @param data fitted data * @return the chart */ JFreeChart createChart(final int bins, final double timeInc, final double[] values) { // create chart data createDataset(bins, timeInc, values); // make a horizontal axis final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL); timeAxis.setLabel(UNITS_LABEL); timeAxis.setRange(0.0, (bins - 1) * timeInc); // make a vertical axis NumberAxis photonAxis; if (logarithmic) { photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL); } else { photonAxis = new NumberAxis(PHOTON_AXIS_LABEL); } // make an excitation plot final XYSplineRenderer excitationRenderer = new XYSplineRenderer(); excitationRenderer.setSeriesShapesVisible(0, false); excitationRenderer.setSeriesPaint(0, EXCITATION_COLOR); excitationPlot = new XYPlot(excitationDataset, timeAxis, photonAxis, excitationRenderer); excitationPlot.setDomainCrosshairVisible(true); excitationPlot.setRangeCrosshairVisible(true); // now make the top level JFreeChart final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, excitationPlot, true); chart.removeLegend(); return chart; }
From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java
/** * Create a snp interval histogram without any axes * @param intervals//from w ww. j a va 2 s. c o 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 * @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:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java
public static ValueAxis createRangeAxis(RangeAxisConfig rangeAxisConfig, PlotInstance plotInstance) throws ChartPlottimeException { if (rangeAxisConfig.getValueType() == ValueType.UNKNOWN || rangeAxisConfig.getValueType() == ValueType.INVALID) { return null; } else {//w w w. ja v a 2s.co m RangeAxisData rangeAxisData = plotInstance.getPlotData().getRangeAxisData(rangeAxisConfig); double initialUpperBound = rangeAxisData.getUpperViewBound(); double initialLowerBound = rangeAxisData.getLowerViewBound(); double upperBound = initialUpperBound; double lowerBound = initialLowerBound; // fetch old zooming LinkAndBrushMaster linkAndBrushMaster = plotInstance.getMasterPlotConfiguration() .getLinkAndBrushMaster(); Range axisZoom = linkAndBrushMaster.getRangeAxisZoom(rangeAxisConfig, plotInstance.getCurrentPlotConfigurationClone()); List<ValueSource> valueSources = rangeAxisConfig.getValueSources(); if (rangeAxisConfig.hasAbsolutStackedPlot()) { for (ValueSource valueSource : valueSources) { VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType(); if (seriesType == VisualizationType.BARS || seriesType == VisualizationType.AREA) { if (valueSource.getSeriesFormat().getStackingMode() == StackingMode.ABSOLUTE) { Pair<Double, Double> minMax = calculateUpperAndLowerBounds(valueSource, plotInstance); if (upperBound < minMax.getSecond()) { upperBound = minMax.getSecond(); } if (lowerBound > minMax.getFirst()) { lowerBound = minMax.getFirst(); } } } } } double margin = upperBound - lowerBound; if (lowerBound == upperBound) { margin = lowerBound; } if (margin == 0) { margin = 0.1; } double normalPad = RangeAxisConfig.padFactor * margin; if (rangeAxisConfig.isLogarithmicAxis()) { if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) { lowerBound -= RangeAxisConfig.logPadFactor * lowerBound; } if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) { upperBound += RangeAxisConfig.logPadFactor * upperBound; } } else { // add margin if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) { lowerBound -= normalPad; } if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) { upperBound += normalPad; } } boolean includeZero = false; if (isIncludingZero(rangeAxisConfig, initialLowerBound) && !rangeAxisConfig.isUsingUserDefinedLowerViewBound()) { // if so set lower bound to zero lowerBound = 0.0; includeZero = true; } boolean upToOne = false; // if there are only relative plots set upper Bound to 1.0 if (rangeAxisConfig.mustHaveUpperBoundOne(initialUpperBound) && !rangeAxisConfig.isUsingUserDefinedUpperViewBound()) { upperBound = 1.0; upToOne = true; } if (includeZero && !upToOne) { upperBound *= 1.05; } String label = rangeAxisConfig.getLabel(); if (label == null) { label = I18N.getGUILabel("plotter.unnamed_value_label"); } ValueAxis rangeAxis; if (rangeAxisConfig.getValueType() == ValueType.NOMINAL && !valueSources.isEmpty()) { // get union of distinct values of all plotValueConfigs on range axis int maxValue = Integer.MIN_VALUE; for (ValueSource valueSource : rangeAxisData.getRangeAxisConfig().getValueSources()) { ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); double maxValueInSource = valueSourceData.getMaxValue(); if (maxValueInSource > maxValue) { maxValue = (int) maxValueInSource; } } Vector<String> yValueStrings = new Vector<String>(maxValue); yValueStrings.setSize(maxValue + 1); ValueSourceData valueSourceData = plotInstance.getPlotData() .getValueSourceData(valueSources.get(0)); for (int i = 0; i <= maxValue; ++i) { yValueStrings.set(i, valueSourceData.getStringForValue(SeriesUsageType.MAIN_SERIES, i)); } String[] yValueStringArray = new String[yValueStrings.size()]; int i = 0; for (String s : yValueStrings) { yValueStringArray[i] = s; ++i; } CustomSymbolAxis symbolRangeAxis = new CustomSymbolAxis(null, yValueStringArray); symbolRangeAxis.setVisible(true); symbolRangeAxis.setAutoRangeIncludesZero(false); symbolRangeAxis.saveUpperBound(upperBound, initialUpperBound); symbolRangeAxis.saveLowerBound(lowerBound, initialLowerBound); symbolRangeAxis.setLabel(label); Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont(); if (axesFont != null) { symbolRangeAxis.setLabelFont(axesFont); symbolRangeAxis.setTickLabelFont(axesFont); } // set range if axis has been zoomed before if (axisZoom != null) { symbolRangeAxis.setRange(axisZoom); } rangeAxis = symbolRangeAxis; } else if (rangeAxisConfig.getValueType() == ValueType.NUMERICAL) { NumberAxis numberRangeAxis; if (rangeAxisConfig.isLogarithmicAxis()) { if (rangeAxisData.getMinYValue() <= 0) { throw new ChartPlottimeException("log_axis_contains_zero", label); } numberRangeAxis = new CustomLogarithmicAxis(null); ((CustomLogarithmicAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound); ((CustomLogarithmicAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound); } else { numberRangeAxis = new CustomNumberAxis(); ((CustomNumberAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound); ((CustomNumberAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound); } numberRangeAxis.setAutoRangeIncludesZero(false); numberRangeAxis.setVisible(true); numberRangeAxis.setLabel(label); Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont(); if (axesFont != null) { numberRangeAxis.setLabelFont(axesFont); numberRangeAxis.setTickLabelFont(axesFont); } // set range if axis has been zoomed before if (axisZoom != null) { numberRangeAxis.setRange(axisZoom); } rangeAxis = numberRangeAxis; } else if (rangeAxisConfig.getValueType() == ValueType.DATE_TIME) { CustomDateAxis dateRangeAxis; if (rangeAxisConfig.isLogarithmicAxis()) { throw new ChartPlottimeException("logarithmic_not_supported_for_value_type", label, ValueType.DATE_TIME); } else { dateRangeAxis = new CustomDateAxis(); } dateRangeAxis.saveUpperBound(upperBound, initialUpperBound); dateRangeAxis.saveLowerBound(lowerBound, initialLowerBound); dateRangeAxis.setVisible(true); dateRangeAxis.setLabel(label); Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont(); if (axesFont != null) { dateRangeAxis.setLabelFont(axesFont); } // set range if axis has been zoomed before if (axisZoom != null) { dateRangeAxis.setRange(axisZoom); } rangeAxis = dateRangeAxis; } else { throw new RuntimeException("Unknown value type. This should not happen"); } // configure format formatAxis(plotInstance.getCurrentPlotConfigurationClone(), rangeAxis); return rangeAxis; } }
From source file:desmoj.extensions.grafic.util.Plotter.java
/** * configure range axis ( lowerBound, upperBound, label, format ticks) * of time-series chart//from ww w. ja v a2 s. com * @param numberAxis * @param label */ private void configureRangeAxis(NumberAxis numberAxis, String label) { double min = numberAxis.getLowerBound(); double max = numberAxis.getUpperBound(); Double delta = 0.01 * (max - min); numberAxis.setLowerBound(min - delta); numberAxis.setUpperBound(max + delta); numberAxis.setLabel(label); // format Ticks double fontHeight = numberAxis.getTickLabelFont().getLineMetrics("X", this.frc).getHeight(); double maxTicks = this.paintPanel.getSize().height / fontHeight; int digits = Math.max(0, (int) -Math.floor(Math.log10((max - min) / maxTicks))); //System.out.println(fontHeight+" "+digits+" "+Math.log10((max - min)/ maxTicks)); NumberFormat formatter = NumberFormat.getNumberInstance(this.locale); formatter.setMinimumFractionDigits(digits); formatter.setMaximumFractionDigits(digits); formatter.setGroupingUsed(true); numberAxis.setNumberFormatOverride(formatter); }
From source file:org.eumetsat.metop.visat.IasiInfoView.java
private void configureSpectrumPlotXAxis(NumberAxis axis) { axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setLabel("Wavenumber (cm-1)"); axis.setRange(new Range(645.0, 2760.0), true, false); }
From source file:org.eumetsat.metop.visat.IasiInfoView.java
private void configureSpectrumPlotYAxis(NumberAxis axis) { axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setLabel("Brightness Temperature (K)"); axis.setRange(new Range(180.0, 320.0), true, false); }
From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java
private JFreeChart createChart(XYDataset dataset, boolean createLegend) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label dataset, // data PlotOrientation.VERTICAL, createLegend, // include legend true, // tooltips false // urls );//from www . ja va 2s. 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); DeviationRenderer renderer = new DeviationRenderer(true, false); // colors if (dataset.getSeriesCount() == 1) { renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d)); } else { // special case needed for avoiding devision by zero for (int i = 0; i < dataset.getSeriesCount(); i++) { renderer.setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesPaint(i, getColorProvider().getPointColor(1.0d - i / (double) (dataset.getSeriesCount() - 1))); } } // background for bounds if (plotBounds) { float[] dashArray = new float[] { 7, 14 }; renderer.setSeriesStroke(boundsSeriesIndex, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dashArray, 0)); renderer.setSeriesPaint(boundsSeriesIndex, Color.GRAY.brighter()); renderer.setSeriesFillPaint(boundsSeriesIndex, Color.GRAY); } // alpha renderer.setAlpha(0.25f); plot.setRenderer(renderer); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); if (axis[INDEX] < 0) { xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); xAxis.setLabel(SERIESINDEX_LABEL); Range range = getRangeForName(SERIESINDEX_LABEL); if (range == null) { xAxis.setAutoRange(true); xAxis.setAutoRangeStickyZero(false); xAxis.setAutoRangeIncludesZero(false); } else { xAxis.setRange(range, true, false); } } else { xAxis.setLabel(dataTable.getColumnName(axis[INDEX])); Range range = getRangeForDimension(axis[INDEX]); if (range == null) { xAxis.setAutoRange(true); xAxis.setAutoRangeStickyZero(false); xAxis.setAutoRangeIncludesZero(false); } else { xAxis.setRange(range, true, false); } } xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel(VALUEAXIS_LABEL); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); setYAxisRange(yAxis); yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); return chart; }
From source file:no.met.jtimeseries.MeteogramWrapper.java
/** * Reset bound when both air temperature and dew point temperature are shown * @param model//from w w w .j ava 2s .co m * @param plotter */ private void resetBoundForTemperature(GenericDataModel model, ChartPlotter plotter) { NumberPhenomenon temperature = model.getNumberPhenomenon(PhenomenonName.AirTemperature.toString()); NumberPhenomenon dewtemperature = model.getNumberPhenomenon(PhenomenonName.dewPointTemperature.toString()); double minValue = temperature.getMinValue() <= dewtemperature.getMinValue() ? temperature.getMinValue() : dewtemperature.getMinValue(); double maxValue = temperature.getMaxValue() >= dewtemperature.getMaxValue() ? temperature.getMaxValue() : dewtemperature.getMaxValue(); NumberAxis numberAxis1 = (NumberAxis) plotter.getPlot().getRangeAxis(plotter.getPlotIndex() - 2); numberAxis1.setLabel(messages.getString("parameter.temperature")); ChartPlotter.setAxisBound(numberAxis1, maxValue, minValue, 8, BACKGROUND_LINES); NumberAxis numberAxis2 = (NumberAxis) plotter.getPlot().getRangeAxis(plotter.getPlotIndex() - 1); numberAxis2.setLabel(messages.getString("parameter.temperature")); numberAxis2.setUpperBound(numberAxis1.getUpperBound()); numberAxis2.setLowerBound(numberAxis1.getLowerBound()); numberAxis2.setTickUnit(numberAxis1.getTickUnit()); numberAxis2.setVisible(false); //Add labels on the curves NumberValueItem airItem = (NumberValueItem) temperature.getItems().get(0); NumberValueItem dewpointItem = (NumberValueItem) dewtemperature.getItems().get(0); plotter.getPlot().getRenderer() .addAnnotation(ChartPlotter.createTextAnnotation(messages.getString("label.air"), temperature.getStartTime().getTime(), airItem.getValue() + 0.1d, TextAnchor.BOTTOM_LEFT, Color.RED), Layer.BACKGROUND); plotter.getPlot().getRenderer() .addAnnotation(ChartPlotter.createTextAnnotation(messages.getString("label.dewpoint"), dewtemperature.getStartTime().getTime(), dewpointItem.getValue() + 0.1d, TextAnchor.BOTTOM_LEFT, Color.ORANGE), Layer.BACKGROUND); }
From source file:no.met.jtimeseries.MeteogramWrapper.java
private void plotPressure(GenericDataModel model, ChartPlotter plotter) { NumberPhenomenon pressure = model.getNumberPhenomenon(PhenomenonName.Pressure.toString()); Color pressureColor = new Color(11, 164, 42); // number axis to be used for pressure plot NumberAxis numberAxis = new NumberAxis(); numberAxis.setLabelPaint(pressureColor); numberAxis.setTickLabelPaint(pressureColor); numberAxis.setLabel(messages.getString("parameter.pressure") + " (hPa)"); double lowBound = 950; double upperBound = 1050; numberAxis.setLowerBound(lowBound);/*from w w w . ja v a2s . c om*/ numberAxis.setUpperBound(upperBound); double tickUnit = (upperBound - lowBound) / BACKGROUND_LINES; numberAxis.setTickUnit(new NumberTickUnit(tickUnit)); PlotStyle plotStyle = new PlotStyle.Builder("Pressure (hPa)").seriesColor(pressureColor) .plusDegreeColor(pressureColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(1.3f)) .numberAxis(numberAxis).build(); plotter.addThresholdLineChart(TimeBase.SECOND, pressure, plotStyle); }
From source file:no.met.jtimeseries.MeteogramWrapper.java
private void plotTemperature(GenericDataModel model, ChartPlotter plotter) { NumberPhenomenon temperature = model.getNumberPhenomenon(PhenomenonName.AirTemperature.toString()); Color temperatureColor = Color.RED; // number axis to be used for wind speed plot NumberAxis numberAxis = new NumberAxis(); numberAxis.setLabelPaint(temperatureColor); numberAxis.setTickLabelPaint(temperatureColor); numberAxis.setLabel(messages.getString("parameter.airTemperature") + " (\u00B0 C)"); double maxValue = temperature.getMaxValue(); double minValue = temperature.getMinValue(); ChartPlotter.setAxisBound(numberAxis, maxValue, minValue, 8, BACKGROUND_LINES); PlotStyle plotStyle = new PlotStyle.Builder("AirTemperature").seriesColor(temperatureColor) .plusDegreeColor(temperatureColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f)) .numberAxis(numberAxis).build(); plotter.addThresholdLineChart(TimeBase.SECOND, temperature, plotStyle); }