/** Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { NumberAxis a1 = new NumberAxis("Test"); NumberAxis a2 = new NumberAxis("Test"); assertTrue(a1.equals(a2)); // private boolean autoRangeIncludesZero; a1.setAutoRangeIncludesZero(false); assertFalse(a1.equals(a2)); a2.setAutoRangeIncludesZero(false); assertTrue(a1.equals(a2)); // private boolean autoRangeStickyZero; a1.setAutoRangeStickyZero(false); assertFalse(a1.equals(a2)); a2.setAutoRangeStickyZero(false); assertTrue(a1.equals(a2)); // private NumberTickUnit tickUnit; a1.setTickUnit(new NumberTickUnit(25.0)); assertFalse(a1.equals(a2)); a2.setTickUnit(new NumberTickUnit(25.0)); assertTrue(a1.equals(a2)); // private NumberFormat numberFormatOverride; a1.setNumberFormatOverride(new DecimalFormat("0.00")); assertFalse(a1.equals(a2)); a2.setNumberFormatOverride(new DecimalFormat("0.00")); assertTrue(a1.equals(a2)); }
private static JFreeChart createChart(XYDataset dataset, String exp) { JFreeChart chart = ChartFactory.createXYLineChart( "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBorderVisible(false); chart.setAntiAlias(true); chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.WHITE); // 网格线颜色 plot.setNoDataMessage("No data!"); plot.setOutlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0.01, (float) 0.91)); // xylineandshaperenderer.setShapesFilled(true); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRange(true); axis.setPositiveArrowVisible(true); axis.setAutoRangeIncludesZero(true); axis.setAutoRangeStickyZero(true); // List axisIndices = Arrays.asList(new Integer[] {new Integer(0), // new Integer(1)}); // plot.mapDatasetToDomainAxes(0, axisIndices); // plot.mapDatasetToRangeAxes(0, axisIndices); // ChartUtilities.applyCurrentTheme(chart); return chart; }
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 ); 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; }