List of usage examples for org.jfree.chart.axis LogarithmicAxis LogarithmicAxis
public LogarithmicAxis(String label)
From source file:org.matsim.counts.algorithms.graphs.CountsSimReal24Graph.java
@Override public JFreeChart createChart(final int nbr) { XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<>(); final ArrayList<String> tooltips = new ArrayList<>(); List<Comp> comps = new Vector<>(); //-------------------- CountSimComparisonLinkFilter linkFilter = new CountSimComparisonLinkFilter(this.ccl_); final Vector<Id<Link>> linkIds = new CountSimComparisonLinkFilter(this.ccl_).getLinkIds(); Iterator<Id<Link>> id_it = linkIds.iterator(); double maxCountValue = 0.1; double maxSimValue = 0.1; // yyyy PtCountsKMLWriterTest.testPtAlightKMLCreation never touches these and then leads to an exception later // when they are zero. Don't know why. kai, sep'16 while (id_it.hasNext()) { Id<Link> id = id_it.next(); double countVal = linkFilter.getAggregatedCountValue(id); double simVal = linkFilter.getAggregatedSimValue(id); if (countVal > 100.0 && simVal > 100.0) { if (countVal > maxCountValue) maxCountValue = countVal; if (simVal > maxSimValue) maxSimValue = simVal;//from w ww . ja v a 2 s. c om series.add(countVal, simVal); comps.add(new Comp(countVal, "link" + id + ".html", "Link " + id + "; " + "Count: " + countVal + ", Sim: " + simVal)); } else { /* values with simVal<100.0 or countVal<100.0 are drawn on the x==100 or/and y==100-line */ countVal = Math.max(100.0, countVal); simVal = Math.max(100.0, simVal); series_outliers.add(countVal, simVal); if (countVal > maxCountValue) maxCountValue = countVal; if (simVal > maxSimValue) maxSimValue = simVal; } } //while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "Avg. Weekday Traffic Volumes, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes", // x axis label "Sim Volumes", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/24h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/24h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); //regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); //outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); Gbl.assertIf(maxCountValue > 0.); dataset1.addSeries("f1x", new double[][] { { 100.0, maxCountValue }, { 100.0, maxCountValue } }); dataset1.addSeries("f2x", new double[][] { { 100.0, maxCountValue }, { 200.0, 2 * maxCountValue } }); dataset1.addSeries("f05x", new double[][] { { 200.0, maxCountValue }, { 100.0, 0.5 * maxCountValue } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", maxCountValue, 2 * maxCountValue); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", maxCountValue, maxCountValue); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", maxCountValue, 0.5 * maxCountValue); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); //plot.getRangeAxis().setRange(1.0, 19000.0); //plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.LogLinChartUIComponent.java
/*********************************************************************************************** * Customise the XYPlot of a new chart, e.g. for fixed range axes. * * @param datasettype/*from w w w. ja v a 2s .c o m*/ * @param primarydataset * @param secondarydatasets * @param updatetype * @param displaylimit * @param channelselector * @param debug * * @return JFreeChart */ public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final String SOURCE = "LogLinChartUIComponent.createCustomisedChart "; final JFreeChart jFreeChart; LOGGER.debug(debug, SOURCE + "--> ChartHelper.createChart()"); MetadataHelper.showMetadataList(getMetadata(), SOURCE + " CHART METADATA --> ChartHelper.createChart()", LOADER_PROPERTIES.isMetadataDebug()); channelselector.debugSelector(debug, SOURCE); // Creates TimeSeriesChart or XYLineChart to suit the dataset // The default renderer is an XYLineAndShapeRenderer jFreeChart = ChartHelper.createChart(primarydataset, ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug), getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit, channelselector, debug); if (jFreeChart != null) { // Customise the Chart for LogLin data if possible if ((hasLogarithmicMode()) && (!channelselector.isLinearMode())) { final XYPlot plot; final LogarithmicAxis axisLog; final String strAxisLabel; LOGGER.debug(debug, SOURCE + "Customise the Chart for LogLin data"); // The set of Metadata available should include the Instrument // and any items from the current observation strAxisLabel = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO); // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis axisLog = new LogarithmicAxis(strAxisLabel); axisLog.setAllowNegativesFlag(true); axisLog.setLog10TickLabelsFlag(true); if ((canAutorange()) && (channelselector.isAutoranging())) { axisLog.setAutoRange(true); axisLog.configure(); axisLog.autoAdjustRange(); } else { axisLog.setRange(getLogarithmicFixedMinY(), getLogarithmicFixedMaxY()); axisLog.configure(); axisLog.autoAdjustRange(); } plot = jFreeChart.getXYPlot(); plot.setRangeAxis(INDEX_AXIS, axisLog); plot.setRangeAxisLocation(INDEX_AXIS, AxisLocation.BOTTOM_OR_LEFT); // Map the dataset to the axis plot.setDataset(INDEX_DATA, primarydataset); plot.mapDatasetToRangeAxis(INDEX_DATA, INDEX_AXIS); // Change the DateAxis format if (DatasetType.TIMESTAMPED.equals(datasettype)) { final DateAxis axisDate; // Customise the DomainAxis at index 0 axisDate = (DateAxis) plot.getDomainAxis(); // Showing the YYYY-MM-DD makes a very long label... axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); } // Now customise the data renderer to improve legend visibility ChartUIHelper.customisePlotRenderer(plot, 0); } else { final XYPlot plot; LOGGER.debug(debug, SOURCE + "Customise the Chart for Linear data"); // Linear Mode // A default range suitable for display of dB ChartHelper.handleAutorangeForLinearMode(jFreeChart, channelselector, canAutorange(), getLinearFixedMinY(), getLinearFixedMaxY(), debug); // Now customise the data renderer to improve legend visibility plot = jFreeChart.getXYPlot(); ChartUIHelper.customisePlotRenderer(plot, 0); } } else { LOGGER.debug(debug, SOURCE + "Chart is NULL"); } return (jFreeChart); }
From source file:org.matsim.pt.counts.PtCountsSimRealPerHourGraph.java
/** * @param hour//from w w w .j av a2s .c om * A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 * a.m. ... */ @Override public JFreeChart createChart(final int hour) { this.hour = hour; XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<String> tooltips = new ArrayList<String>(); List<Comp> comps = new Vector<Comp>(); Iterator<CountSimComparison> l_it = this.ccl_.iterator(); // int elementCounter=0; while (l_it.hasNext()) { CountSimComparison cc = l_it.next(); /* * values with simVal==0.0 or countVal==0.0 are drawn on the x==1 * or/and y==1-line Such values are the result of a poor simulation * run, but they can also represent a valid result (closing summer * road during winter time) */ if (cc.getHour() == hour) { // elementCounter++; double realVal = 1.0; double simVal = 1.0; if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) { realVal = cc.getCountValue(); simVal = cc.getSimulationValue(); series.add(realVal, simVal); comps.add(new Comp(realVal, "link" + cc.getId() + ".html", "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal)); } else { realVal = Math.max(1.0, cc.getCountValue()); simVal = Math.max(1.0, cc.getSimulationValue()); series_outliers.add(realVal, simVal); } } // if } // while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); /* * first we have to sort the vector according to the rendering ordering * (which is the x value). REALLY??? After hours of searching no better * solution found! please help! */ Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label "Sim Volumes [veh/h]", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); // regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); // outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } }); dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } }); dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); plot.getRangeAxis().setRange(1.0, 19000.0); plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:org.matsim.pt.counts.obsolete.PtCountsSimRealPerHourGraph.java
/** * @param hour/* w w w . j av a 2s.c o m*/ * A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 * a.m. ... */ @Override @Deprecated // use standard counts package public JFreeChart createChart(final int hour) { this.hour = hour; XYSeriesCollection dataset0 = new XYSeriesCollection(); XYSeries series = new XYSeries("MATSim volumes"); // easier to use another dataset XYSeriesCollection dataset_outliers = new XYSeriesCollection(); XYSeries series_outliers = new XYSeries("MATSim outliers"); CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<String> tooltips = new ArrayList<String>(); List<Comp> comps = new Vector<Comp>(); Iterator<CountSimComparison> l_it = this.ccl_.iterator(); // int elementCounter=0; while (l_it.hasNext()) { CountSimComparison cc = l_it.next(); /* * values with simVal==0.0 or countVal==0.0 are drawn on the x==1 * or/and y==1-line Such values are the result of a poor simulation * run, but they can also represent a valid result (closing summer * road during winter time) */ if (cc.getHour() == hour) { // elementCounter++; double realVal = 1.0; double simVal = 1.0; if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) { realVal = cc.getCountValue(); simVal = cc.getSimulationValue(); series.add(realVal, simVal); comps.add(new Comp(realVal, "link" + cc.getId() + ".html", "Link " + cc.getId() + "; " + "Count: " + realVal + ", Sim: " + simVal)); } else { realVal = Math.max(1.0, cc.getCountValue()); simVal = Math.max(1.0, cc.getSimulationValue()); series_outliers.add(realVal, simVal); } } // if } // while dataset0.addSeries(series); dataset_outliers.addSeries(series_outliers); /* * first we have to sort the vector according to the rendering ordering * (which is the x value). REALLY??? After hours of searching no better * solution found! please help! */ Collections.sort(comps, new MyComparator()); for (Iterator<Comp> iter = comps.iterator(); iter.hasNext();) { Comp cp = iter.next(); urls.add(cp.getURL()); tooltips.add(cp.getTooltip()); } url_gen.addURLSeries(urls); tt_gen.addToolTipSeries(tooltips); String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_; this.setChartTitle(title); this.chart_ = ChartFactory.createXYLineChart(title, "Count Volumes [veh/h]", // x axis label "Sim Volumes [veh/h]", // y axis label dataset0, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips true // urls ); XYPlot plot = this.chart_.getXYPlot(); final LogarithmicAxis axis_x = new LogarithmicAxis("Count Volumes [veh/h]"); final LogarithmicAxis axis_y = new LogarithmicAxis("Sim Volumes [veh/h]"); axis_x.setAllowNegativesFlag(false); axis_y.setAllowNegativesFlag(false); // regular values XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLinesVisible(false); renderer.setURLGenerator(url_gen); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesToolTipGenerator(0, tt_gen); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); // outliers XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setLinesVisible(false); renderer2.setSeriesPaint(0, Color.red); renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); // error band DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, { 1.0, 10000.0 } }); dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, { 2.0, 20000.0 } }); dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, { 1.0, 5000.0 } }); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); renderer3.setShapesVisible(false); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.blue); renderer3.setSeriesPaint(2, Color.blue); renderer3.setBaseSeriesVisibleInLegend(false); renderer3.setSeriesItemLabelsVisible(0, true); renderer3.setSeriesItemLabelsVisible(1, false); renderer3.setSeriesItemLabelsVisible(2, false); XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", 12000.0, 15500.0); annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation0); XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation1); XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", 11000.0, 3500.0); annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); plot.addAnnotation(annotation2); plot.setDomainAxis(axis_x); plot.setRangeAxis(axis_y); plot.setRenderer(0, renderer); plot.setRenderer(1, renderer2); plot.setDataset(1, dataset_outliers); plot.setRenderer(2, renderer3); plot.setDataset(2, dataset1); plot.getRangeAxis().setRange(1.0, 19000.0); plot.getDomainAxis().setRange(1.0, 19000.0); return this.chart_; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GOESChartUIComponent.java
/*********************************************************************************************** * Customise the XYPlot of a new chart, e.g. for fixed range axes. * * @param datasettype//w w w. jav a 2 s . c om * @param primarydataset * @param secondarydatasets * @param updatetype * @param displaylimit * @param channelselector * @param debug * * @return JFreeChart */ public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final JFreeChart jFreeChart; // A plain Chart is an XYPlot // with a DateAxis for the x-axis (index 0) and a NumberAxis for the y-axis (index 0). // The default renderer is an XYLineAndShapeRenderer jFreeChart = ChartHelper.createChart(primarydataset, ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug), getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit, channelselector, debug); // Customise the Chart for GOES data // Channels 0 & 1 are Data on a LogarithmicAxis, // Channel 2 is Ratio on a NumberAxis if (jFreeChart != null) { final String strLabelFlux; final String strLabelRatio; final XYPlot plot; final LogarithmicAxis axisFlux; final DateAxis axisDate; // The set of Metadata available should include the Instrument // and any items from the current observation strLabelFlux = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO); strLabelRatio = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ONE); plot = jFreeChart.getXYPlot(); //---------------------------------------------------------------------------------- // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis // The RangeAxis at index 0 is the LogarithmicAxis, to be used by Channels 0 & 1 (Data) axisFlux = new LogarithmicAxis(strLabelFlux); axisFlux.setRange(1.0E-09, 1.0E-02); axisFlux.setAllowNegativesFlag(false); axisFlux.setLog10TickLabelsFlag(true); plot.setRangeAxis(0, axisFlux); // Map the dataset to the axis plot.setDataset(INDEX_FLUX, primarydataset); plot.mapDatasetToRangeAxis(0, 0); plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); //---------------------------------------------------------------------------------- // Customise the DomainAxis at index 0 axisDate = (DateAxis) plot.getDomainAxis(); // Showing the YYYY-MM-DD makes a very long label... // ToDo Consider ThreadLocal axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); // Now customise the Flux renderer to improve legend visibility // Use the same colours as on http://www.swpc.noaa.gov/ // blue=0.5 - 4.0A red=1.0 - 8.0A ChartUIHelper.customisePlotRenderer(plot, INDEX_FLUX); //---------------------------------------------------------------------------------- // Set the RangeAxis at index 1 to a new NumberAxis, to be used by Channel 2 (Ratio) if ((secondarydatasets != null) && (secondarydatasets.size() == 1)) { final NumberAxis axisRatio; final XYLineAndShapeRenderer rendererRatio; axisRatio = new NumberAxis(strLabelRatio); plot.setRangeAxis(1, axisRatio); // The RangeAxis at index 1 is the NumberAxis, to be used by Channel 2 plot.setDataset(INDEX_RATIO, secondarydatasets.get(0)); plot.mapDatasetToRangeAxis(1, 1); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); rendererRatio = new XYLineAndShapeRenderer(); rendererRatio.setLinesVisible(true); rendererRatio.setShapesVisible(false); // Channel 2 is Ratio rendererRatio.setSeriesPaint(0, ChartUIHelper.getStandardColour(2).getColor()); rendererRatio.setLegendLine(SHAPE_LEGEND); plot.setRenderer(INDEX_RATIO, rendererRatio); //ChartHelper.customisePlotRenderer(plot, INDEX_RATIO); } } return (jFreeChart); }
From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PlotCreator.java
private NumberAxis createAxis(final AxisType axisType, final String axisLabel) { NumberAxis numberAxis = axisType.equals(AxisType.LOGARITHMIC) ? new LogarithmicAxis(axisLabel) : new NumberAxis(axisLabel); numberAxis.setNumberFormatOverride((NumberFormat) numberFormat.clone()); return numberAxis; }
From source file:loci.slim.ui.ExcitationGraph.java
/** * Creates the chart/*from www . jav a 2s .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:loci.slim2.process.interactive.ui.DefaultExcitationGraph.java
/** * Creates the chart/*from ww w . jav a 2s. 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:net.sourceforge.subsonic.controller.FolderChartController.java
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) { JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);//ww w. j a v a 2 s . c om CategoryPlot plot = chart.getCategoryPlot(); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.gray); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); LogarithmicAxis rangeAxis = new LogarithmicAxis(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setAllowNegativesFlag(true); // rangeAxis.setTickUnit(new NumberTickUnit(.1, new DecimalFormat("##0%"))); plot.setRangeAxis(rangeAxis); // Disable bar outlines. BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // Set up gradient paint for series. GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64)); renderer.setSeriesPaint(0, gp0); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 11)); renderer.setItemLabelAnchorOffset(-45.0); renderer.setSeriesItemLabelPaint(0, Color.white); renderer.setBaseItemLabelPaint(Color.white); // Rotate labels. CategoryAxis domainAxis = plot.getDomainAxis(); // domainAxis.setCategoryLabelPositions(); // domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); return chart; }
From source file:mil.tatrc.physiology.biogears.verification.ScenarioPlotTool.java
public void createGraph(String toDir, Paint color, String title, String XAxisLabel, String YAxisLabel, XYSeries... xyData) {// w ww.ja v a 2 s . c o m new File(toDir).mkdir(); Log.info("Creating Graph " + toDir + title); double resMin0 = 1.e6; double resMax0 = -1.e6; double resMin1 = 1.e6; double resMax1 = -1.e6; XYSeriesCollection dataSet = new XYSeriesCollection(); for (XYSeries data : xyData) dataSet.addSeries(data); JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title XAxisLabel, // x axis label YAxisLabel, // y axis label dataSet, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); if (title.contains("Residual")) { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); if (Math.abs(xyData[0].getMinY()) > Math.abs(xyData[0].getMaxY())) resMax0 = Math.abs(resMin0); if (Math.abs(xyData[0].getMaxY()) > Math.abs(xyData[0].getMinY())) resMin0 = -1.0 * Math.abs(resMax0); if ((resMin0 == 0.0) && (resMax0 == 0.0)) { resMin0 = -0.00001; resMax0 = 0.00001; } ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly } else if (title.contains("Error")) { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); if ((resMin0 == 0.0) && (resMax0 == 0.0)) { resMin0 = -0.00001; resMax0 = 0.00001; } if (resMin0 >= 0.0) resMin0 = -0.01; ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly /* yAxis.setTickLabelPaint(new Color(1,0,0)); yAxis.setTickMarkPaint(new Color(1,0,0)); yAxis.setAxisLinePaint(new Color(1,0,0)); yAxis.setLabelPaint(new Color(1,0,0)); ValueAxis xAxis = plot.getDomainAxis(); xAxis.setTickLabelPaint(new Color(1,0,0)); xAxis.setTickMarkPaint(new Color(1,0,0)); yAxis.setAxisLinePaint(new Color(1,0,0)); yAxis.setLabelPaint(new Color(1,0,0)); */ } else { if (xyData.length > 1) { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); resMax1 = xyData[1].getMaxY(); resMin1 = xyData[1].getMinY(); if (resMin1 < resMin0) resMin0 = resMin1; if (resMax1 > resMax0) resMax0 = resMax1; if ((resMin0 == 0.0) && (resMax0 == 0.0)) { resMin0 = -0.00001; resMax0 = 0.00001; } if (resMin0 >= 0.0) resMin0 = -0.01; if (YAxisLabel.indexOf("PlasmaConcentration") > -1) plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")")); else { ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly } } else { // Make plot symmetric about x axis resMax0 = xyData[0].getMaxY(); resMin0 = xyData[0].getMinY(); if ((resMin0 == 0.0) && (resMax0 == 0.0)) { resMin0 = -0.00001; resMax0 = 0.00001; } if (resMin0 >= 0.0) resMin0 = -0.01; if (YAxisLabel.indexOf("PlasmaConcentration") > -1) plot.setRangeAxis(new LogarithmicAxis("Log(" + YAxisLabel + ")")); else { ValueAxis yAxis = plot.getRangeAxis(); yAxis.setRange(resMin0 + 0.05 * resMin0, resMax0 + 0.05 * resMax0);//5% buffer so we can see top and bottom clearly } } } formatXYPlot(chart, color); //Changing line widths and colors XYItemRenderer r = plot.getRenderer(); BasicStroke wideLine = new BasicStroke(lineWidth); r.setSeriesStroke(0, wideLine); r.setSeriesStroke(1, wideLine); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); if (xyData.length > 1) { renderer.setSeriesStroke(//makes a dashed line 0, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K) new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 15.0f, 30.0f }, 0.0f)); renderer.setDrawSeriesLineAsPath(true); renderer.setUseFillPaint(true); } renderer.setBaseShapesVisible(false); renderer.setSeriesFillPaint(0, expectedLineColor); renderer.setSeriesFillPaint(1, computedLineColor); renderer.setSeriesPaint(0, expectedLineColor); renderer.setSeriesPaint(1, computedLineColor); try { if (toDir == null || toDir.isEmpty()) toDir = "."; File JPGFile = new File(toDir + "/" + StringUtils.removeParens(title) + ".jpg"); ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800); } catch (IOException e) { Log.error(e.getMessage()); } }