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

📄 jfreechartdemobase.java

📁 JfreeChart 常用图表例子
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /**     * Creates and returns a sample vertical 3D bar chart.     *     * @return a sample vertical 3D bar chart.     */    public JFreeChart createVertical3DBarChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("bar.vertical3D.title");        final String domain = this.resources.getString("bar.vertical3D.domain");        final String range = this.resources.getString("bar.vertical3D.range");        final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();        final JFreeChart chart = ChartFactory.createBarChart3D(            title,            domain,            range, data,            PlotOrientation.VERTICAL,            true,            true,            false        );        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));        final CategoryPlot plot = (CategoryPlot) chart.getPlot();        plot.setForegroundAlpha(0.75f);        return chart;    }    /**     * Creates and returns a sample stacked vertical bar chart.     *     * @return a sample stacked vertical bar chart.     */    public JFreeChart createVerticalStackedBarChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("bar.vertical-stacked.title");        final String domain = this.resources.getString("bar.vertical-stacked.domain");        final String range = this.resources.getString("bar.vertical-stacked.range");        final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();        final JFreeChart chart            = ChartFactory.createStackedBarChart(title, domain, range, data,                                                 PlotOrientation.VERTICAL,                                                 true,                                                 true,                                                 false);        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));        return chart;    }    /**     * Creates and returns a sample stacked vertical 3D bar chart.     *     * @return a sample stacked vertical 3D bar chart.     */    public JFreeChart createVerticalStacked3DBarChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("bar.vertical-stacked3D.title");        final String domain = this.resources.getString("bar.vertical-stacked3D.domain");        final String range = this.resources.getString("bar.vertical-stacked3D.range");        final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();        final JFreeChart chart = ChartFactory.createStackedBarChart3D(title, domain, range, data,                                                                PlotOrientation.VERTICAL,                                                                true, true, false);        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));        return chart;    }    /**     * Creates and returns a sample pie chart.     *     * @return a sample pie chart.     */    public JFreeChart createPieChartOne() {        // create a default chart based on some sample data...        final String title = this.resources.getString("pie.pie1.title");        final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();        final PieDataset extracted = DatasetUtilities.createPieDatasetForRow(data, 0);        final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.orange));        final PiePlot plot = (PiePlot) chart.getPlot();        plot.setCircular(false);        // make section 1 explode by 100%...        plot.setExplodePercent(1, 1.00);        return chart;    }    /**     * Creates and returns a sample pie chart.     *     * @return a sample pie chart.     */    public JFreeChart createPieChartTwo() {        // create a default chart based on some sample data...        final String title = this.resources.getString("pie.pie2.title");        final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();        final Comparable category = (Comparable) data.getColumnKeys().get(1);        final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category);        final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);        // then customise it a little...        chart.setBackgroundPaint(Color.lightGray);        final PiePlot pie = (PiePlot) chart.getPlot();        pie.setLabelGenerator(new StandardPieItemLabelGenerator(            "{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()        ));        pie.setBackgroundImage(JFreeChart.INFO.getLogo());        pie.setBackgroundPaint(Color.white);        pie.setBackgroundAlpha(0.6f);        pie.setForegroundAlpha(0.75f);        return chart;    }    /**     * Creates and returns a sample pie chart which compares 2 datasets.     *     * @return a sample pie chart.     * @author <a href="mailto:opensource@objectlab.co.uk">Benoit Xhenseval</a>     * @since 0.9.18     */    public JFreeChart createPieChartThree() {        // create a default chart based on some sample data...        String title = this.resources.getString("pie.pie3.title");        final double[][] data = new double[][]            {{10.0, 4.0, 14.0, 12.0, 12.0},             {9.0, 7.0, 13.7, 15.0, 3.0}};        CategoryDataset dataset = DatasetUtilities.createCategoryDataset(            "Series ", "Category ", data        );        PieDataset extracted = DatasetUtilities.createPieDatasetForRow(dataset, 0);        PieDataset extracted2 = DatasetUtilities.createPieDatasetForRow(dataset, 1);        // generate a basic pie chart with title        // comparing extracted with extracted2        // a difference of 40% or more will trigger maximum brightness in red or green        // true green is for increase        // true for legend        // true for tooltips        // false for urls        // true for subtitle        // true for showing the difference        JFreeChart chart = ChartFactory.createPieChart(            title, extracted, extracted2, 40, true, true, true, false, true, true        );        return chart;    }    /**     * Creates and returns a sample XY plot.     *     * @return a sample XY plot.     */    public JFreeChart createXYPlot() {        // create a default chart based on some sample data...        final String title = this.resources.getString("xyplot.sample1.title");        final String domain = this.resources.getString("xyplot.sample1.domain");        final String range = this.resources.getString("xyplot.sample1.range");        final XYDataset data = DemoDatasetFactory.createSampleXYDataset();        final JFreeChart chart = ChartFactory.createXYLineChart(            title,            domain, range, data,            PlotOrientation.VERTICAL,            true,            true,            false        );        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));        return chart;    }    /**     * Creates and returns a sample time series chart.     *     * @return a sample time series chart.     */    public JFreeChart createTimeSeries1Chart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("timeseries.sample1.title");        final String subtitle = this.resources.getString("timeseries.sample1.subtitle");        final String domain = this.resources.getString("timeseries.sample1.domain");        final String range = this.resources.getString("timeseries.sample1.range");        final String copyrightStr = this.resources.getString("timeseries.sample1.copyright");        final XYDataset data = DemoDatasetFactory.createTimeSeriesCollection3();        final JFreeChart chart = ChartFactory.createTimeSeriesChart(            title, domain, range, data, true, true, false        );        // then customise it a little...        final TextTitle title2 = new TextTitle(subtitle, new Font("SansSerif", Font.PLAIN, 12));  //      title2.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0));        chart.addSubtitle(title2);        final TextTitle copyright = new TextTitle(            copyrightStr, new Font("SansSerif", Font.PLAIN, 9)        );        copyright.setPosition(RectangleEdge.BOTTOM);        copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT);        chart.addSubtitle(copyright);        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));        final XYPlot plot = chart.getXYPlot();        final DateAxis axis = (DateAxis) plot.getDomainAxis();        axis.setVerticalTickLabels(true);        return chart;    }    /**     * Creates and returns a sample time series chart.     *     * @return a sample time series chart.     */    public JFreeChart createTimeSeries2Chart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("timeseries.sample2.title");        final String subtitleStr = this.resources.getString("timeseries.sample2.subtitle");        final String domain = this.resources.getString("timeseries.sample2.domain");        final String range = this.resources.getString("timeseries.sample2.range");        final XYDataset data = DemoDatasetFactory.createTimeSeriesCollection4();        final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data,                                                              true, true, false);        // then customise it a little...        final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));        chart.addSubtitle(subtitle);        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));        final XYPlot plot = chart.getXYPlot();        final LogarithmicAxis rangeAxis = new LogarithmicAxis(range);        plot.setRangeAxis(rangeAxis);        return chart;    }    /**     * Creates and returns a sample time series chart.     *     * @return a sample time series chart.     */    public JFreeChart createTimeSeriesWithMAChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("timeseries.sample3.title");        final String domain = this.resources.getString("timeseries.sample3.domain");        final String range = this.resources.getString("timeseries.sample3.range");        final String subtitleStr = this.resources.getString("timeseries.sample3.subtitle");        final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();        final TimeSeries mav = MovingAverage.createMovingAverage(            jpy, "30 Day Moving Average", 30, 30        );        final TimeSeriesCollection dataset = new TimeSeriesCollection();        dataset.addSeries(jpy);        dataset.addSeries(mav);        final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, dataset,                                                              true,                                                              true,                                                              false);        // then customise it a little...        final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));        chart.addSubtitle(subtitle);        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));        return chart;    }    /**     * Displays a vertical bar chart in its own frame.     *     * @return a high low chart.     */    public JFreeChart createHighLowChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("timeseries.highlow.title");        final String domain = this.resources.getString("timeseries.highlow.domain");        final String range = this.resources.getString("timeseries.highlow.range");        final String subtitleStr = this.resources.getString("timeseries.highlow.subtitle");        final DefaultHighLowDataset data = DemoDatasetFactory.createHighLowDataset();

⌨️ 快捷键说明

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