⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numberaxistests.java

📁 java图形利器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        dataset.setValue(200.0, "Row 1", "Column 2");        JFreeChart chart = ChartFactory.createBarChart(            "Test",             "Categories",            "Value",            dataset,            PlotOrientation.VERTICAL,            false,             false,            false        );        CategoryPlot plot = (CategoryPlot) chart.getPlot();        NumberAxis axis = (NumberAxis) plot.getRangeAxis();        assertEquals(axis.getLowerBound(), 0.0, EPSILON);            assertEquals(axis.getUpperBound(), 210.0, EPSILON);        }        /**     * A simple test for the auto-range calculation looking at a     * NumberAxis used as the range axis for a CategoryPlot.  In this     * case, the 'autoRangeIncludesZero' flag is set to false.     */    public void testAutoRange2() {        DefaultCategoryDataset dataset = new DefaultCategoryDataset();        dataset.setValue(100.0, "Row 1", "Column 1");        dataset.setValue(200.0, "Row 1", "Column 2");        JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",                "Value", dataset, PlotOrientation.VERTICAL, false, false,                false);        CategoryPlot plot = (CategoryPlot) chart.getPlot();        NumberAxis axis = (NumberAxis) plot.getRangeAxis();        axis.setAutoRangeIncludesZero(false);        assertEquals(axis.getLowerBound(), 95.0, EPSILON);            assertEquals(axis.getUpperBound(), 205.0, EPSILON);        }        /**     * A simple test for the auto-range calculation looking at a     * NumberAxis used as the range axis for a CategoryPlot.  In this     * case, the 'autoRangeIncludesZero' flag is set to false AND the     * original dataset is replaced with a new dataset.     */    public void testAutoRange3() {        DefaultCategoryDataset dataset = new DefaultCategoryDataset();        dataset.setValue(100.0, "Row 1", "Column 1");        dataset.setValue(200.0, "Row 1", "Column 2");        JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",                "Value", dataset, PlotOrientation.VERTICAL, false, false,                false);        CategoryPlot plot = (CategoryPlot) chart.getPlot();        NumberAxis axis = (NumberAxis) plot.getRangeAxis();        axis.setAutoRangeIncludesZero(false);        assertEquals(axis.getLowerBound(), 95.0, EPSILON);            assertEquals(axis.getUpperBound(), 205.0, EPSILON);                    // now replacing the dataset should update the axis range...        DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();        dataset2.setValue(900.0, "Row 1", "Column 1");        dataset2.setValue(1000.0, "Row 1", "Column 2");        plot.setDataset(dataset2);        assertEquals(axis.getLowerBound(), 895.0, EPSILON);            assertEquals(axis.getUpperBound(), 1005.0, EPSILON);        }        /**     * A check for the interaction between the 'autoRangeIncludesZero' flag     * and the base setting in the BarRenderer.     */    public void testAutoRange4() {        DefaultCategoryDataset dataset = new DefaultCategoryDataset();        dataset.setValue(100.0, "Row 1", "Column 1");        dataset.setValue(200.0, "Row 1", "Column 2");        JFreeChart chart = ChartFactory.createBarChart("Test", "Categories",                "Value", dataset, PlotOrientation.VERTICAL, false, false,                false);        CategoryPlot plot = (CategoryPlot) chart.getPlot();        NumberAxis axis = (NumberAxis) plot.getRangeAxis();        axis.setAutoRangeIncludesZero(false);        BarRenderer br = (BarRenderer) plot.getRenderer();        br.setIncludeBaseInRange(false);        assertEquals(95.0, axis.getLowerBound(), EPSILON);            assertEquals(205.0, axis.getUpperBound(), EPSILON);                    br.setIncludeBaseInRange(true);        assertEquals(0.0, axis.getLowerBound(), EPSILON);            assertEquals(210.0, axis.getUpperBound(), EPSILON);                    axis.setAutoRangeIncludesZero(true);        assertEquals(0.0, axis.getLowerBound(), EPSILON);            assertEquals(210.0, axis.getUpperBound(), EPSILON);                    br.setIncludeBaseInRange(true);        assertEquals(0.0, axis.getLowerBound(), EPSILON);            assertEquals(210.0, axis.getUpperBound(), EPSILON);            // now replacing the dataset should update the axis range...        DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();        dataset2.setValue(900.0, "Row 1", "Column 1");        dataset2.setValue(1000.0, "Row 1", "Column 2");        plot.setDataset(dataset2);        assertEquals(0.0, axis.getLowerBound(), EPSILON);            assertEquals(1050.0, axis.getUpperBound(), EPSILON);                br.setIncludeBaseInRange(false);        assertEquals(0.0, axis.getLowerBound(), EPSILON);            assertEquals(1050.0, axis.getUpperBound(), EPSILON);                axis.setAutoRangeIncludesZero(false);        assertEquals(895.0, axis.getLowerBound(), EPSILON);            assertEquals(1005.0, axis.getUpperBound(), EPSILON);            }        /**     * Checks that the auto-range for the domain axis on an XYPlot is     * working as expected.     */    public void testXYAutoRange1() {        XYSeries series = new XYSeries("Series 1");        series.add(1.0, 1.0);        series.add(2.0, 2.0);        series.add(3.0, 3.0);        XYSeriesCollection dataset = new XYSeriesCollection();        dataset.addSeries(series);        JFreeChart chart = ChartFactory.createScatterPlot(            "Test",             "X",            "Y",            dataset,            PlotOrientation.VERTICAL,            false,             false,            false        );        XYPlot plot = (XYPlot) chart.getPlot();        NumberAxis axis = (NumberAxis) plot.getDomainAxis();        axis.setAutoRangeIncludesZero(false);        assertEquals(0.9, axis.getLowerBound(), EPSILON);            assertEquals(3.1, axis.getUpperBound(), EPSILON);        }        /**     * Checks that the auto-range for the range axis on an XYPlot is     * working as expected.     */    public void testXYAutoRange2() {        XYSeries series = new XYSeries("Series 1");        series.add(1.0, 1.0);        series.add(2.0, 2.0);        series.add(3.0, 3.0);        XYSeriesCollection dataset = new XYSeriesCollection();        dataset.addSeries(series);        JFreeChart chart = ChartFactory.createScatterPlot(            "Test",             "X",            "Y",            dataset,            PlotOrientation.VERTICAL,            false,             false,            false        );        XYPlot plot = (XYPlot) chart.getPlot();        NumberAxis axis = (NumberAxis) plot.getRangeAxis();        axis.setAutoRangeIncludesZero(false);        assertEquals(0.9, axis.getLowerBound(), EPSILON);            assertEquals(3.1, axis.getUpperBound(), EPSILON);        }    //    /**//     * Some checks for the setRangeType() method.//     *///    public void testSetRangeType() {//        //        NumberAxis axis = new NumberAxis("X");//        axis.setRangeType(RangeType.POSITIVE);//        assertEquals(RangeType.POSITIVE, axis.getRangeType());//        //        // test a change to RangeType.POSITIVE//        axis.setRangeType(RangeType.FULL);//        axis.setRange(-5.0, 5.0);//        axis.setRangeType(RangeType.POSITIVE);//        assertEquals(new Range(0.0, 5.0), axis.getRange());//        //        axis.setRangeType(RangeType.FULL);//        axis.setRange(-10.0, -5.0);//        axis.setRangeType(RangeType.POSITIVE);//        assertEquals(new Range(0.0, axis.getAutoRangeMinimumSize()), //                axis.getRange());////        // test a change to RangeType.NEGATIVE//        axis.setRangeType(RangeType.FULL);//        axis.setRange(-5.0, 5.0);//        axis.setRangeType(RangeType.NEGATIVE);//        assertEquals(new Range(-5.0, 0.0), axis.getRange());        //        //        axis.setRangeType(RangeType.FULL);//        axis.setRange(5.0, 10.0);//        axis.setRangeType(RangeType.NEGATIVE);//        assertEquals(new Range(-axis.getAutoRangeMinimumSize(), 0.0), //                axis.getRange());////        // try null//        boolean pass = false;//        try {//            axis.setRangeType(null);    //        }//        catch (IllegalArgumentException e) {//            pass = true;//        }//        assertTrue(pass);//    }        /**     * Some checks for the setLowerBound() method.     */    public void testSetLowerBound() {        NumberAxis axis = new NumberAxis("X");        axis.setRange(0.0, 10.0);        axis.setLowerBound(5.0);        assertEquals(5.0, axis.getLowerBound(), EPSILON);        axis.setLowerBound(10.0);        assertEquals(10.0, axis.getLowerBound(), EPSILON);        assertEquals(11.0, axis.getUpperBound(), EPSILON);                //axis.setRangeType(RangeType.POSITIVE);        //axis.setLowerBound(-5.0);        //assertEquals(0.0, axis.getLowerBound(), EPSILON);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -