List of usage examples for org.jfree.chart.axis NumberAxis clone
@Override public Object clone() throws CloneNotSupportedException
From source file:edu.ucla.stat.SOCR.chart.demo.DotChart.java
/** * Creates a chart./*from w w w . j av a2 s. c o m*/ * * @param dataset the data for the chart. * * @return a chart. */ protected JFreeChart createChart1(XYDataset dataset) { //System.out.println("createChart1 called"); // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title "", // x axis label domain rangeLabel, // y axis label range dataset, // data PlotOrientation.HORIZONTAL, !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // renderer.setSeriesShape(0, java.awt.Shape.round); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setBaseLinesVisible(false); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); //change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setUpperMargin(0.01); rangeAxis.setLowerMargin(0.01); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setAutoRangeIncludesZero(true); domainAxis.setTickLabelsVisible(false); domainAxis.setTickMarksVisible(false); domainAxis.setUpperMargin(5); domainAxis.setLowerMargin(0.01); // OPTIONAL CUSTOMISATION COMPLETED. setYSummary(dataset); try { // System.out.println("setting the common RangeAxis to null"); common_rangeAxis = null; common_rangeAxis = (NumberAxis) rangeAxis.clone(); // System.out.println("creating the common RangeAxis"); } catch (CloneNotSupportedException e) { System.out.println("CloneNotSupportedException!, exception caught"); } return chart; }
From source file:no.met.jtimeseries.MeteogramWrapper.java
private void plotWindSpeedDirection(GenericDataModel model, ChartPlotter plotter, boolean showWindDirection, String unit, List<Date> symbolTimes) { // plot wind speed NumberPhenomenon windSpeed = model.getNumberPhenomenon(PhenomenonName.WindSpeedMPS.toString()).clone(); Color windSpeedColor = new Color(0, 0, 0); // number axis to be used for wind speed plot NumberAxis numberAxis = new NumberAxis(); numberAxis.setLabelPaint(windSpeedColor); numberAxis.setTickLabelPaint(windSpeedColor); if (unit.equalsIgnoreCase("ms")) { numberAxis.setLabel(messages.getString("parameter.wind") + " (m/s)"); } else {/* w w w. j av a 2 s. c o m*/ windSpeed.scaling(1 / MarinogramPlot.KNOT); numberAxis.setLabel( messages.getString("parameter.wind") + " (" + messages.getString("label.knots") + ")"); NumberFormat formatter = new DecimalFormat("#0.0"); numberAxis.setNumberFormatOverride(formatter); } double maxValue = windSpeed.getMaxValue(); double minValue = windSpeed.getMinValue(); ChartPlotter.setAxisBound(numberAxis, maxValue, minValue, 8, BACKGROUND_LINES); PlotStyle plotStyle = new PlotStyle.Builder("Wind").seriesColor(windSpeedColor) .plusDegreeColor(windSpeedColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f)) .numberAxis(numberAxis).nonNegative(true).build(); plotter.addLineChart(TimeBase.SECOND, windSpeed, plotStyle); // plot wind direction if (showWindDirection) { NumberPhenomenon windDirection = model .getNumberPhenomenon(PhenomenonName.WindDirectionDegree.toString()).clone(); InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes); windDirection.filter(symbolTimesFilter); windSpeed.filter(symbolTimesFilter); // when plot wind direction, the arrow should be rotated 180 degree windDirection = windDirection.transform(180); NumberAxis numberAxisDirection = null; try { numberAxisDirection = (NumberAxis) numberAxis.clone(); } catch (CloneNotSupportedException e) { } numberAxisDirection.setVisible(false); plotter.getPlot().setRangeAxis(plotter.getPlotIndex(), numberAxisDirection); plotter.addArrowDirectionPlot(windDirection, windSpeed, 0.08, plotStyle); // transform back after plot windDirection = windDirection.transform(180); } }