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

📄 jfreechartdemobase.java

📁 JfreeChart 常用图表例子
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        final JFreeChart chart = ChartFactory.createHighLowChart(title, domain, range, data, true);        // 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.magenta));        return chart;    }    /**     * Creates a candlestick chart.     *     * @return a candlestick chart.     */    public JFreeChart createCandlestickChart() {      // create a default chart based on some sample data...      final String title = this.resources.getString("timeseries.candlestick.title");      final String domain = this.resources.getString("timeseries.candlestick.domain");      final String range = this.resources.getString("timeseries.candlestick.range");      final String subtitleStr = this.resources.getString("timeseries.candlestick.subtitle");      final DefaultHighLowDataset data = DemoDatasetFactory.createHighLowDataset();      final JFreeChart chart = ChartFactory.createCandlestickChart(          title, domain, range, data, 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.green));      return chart;    }    /**     * Creates and returns a sample signal chart.     *     * @return a sample chart.     */    public JFreeChart createSignalChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("timeseries.signal.title");        final String domain = this.resources.getString("timeseries.signal.domain");        final String range = this.resources.getString("timeseries.signal.range");        final String subtitleStr = this.resources.getString("timeseries.signal.subtitle");        final SignalsDataset data = DemoDatasetFactory.createSampleSignalDataset();        final JFreeChart chart = ChartFactory.createSignalChart(title, domain, range, data, true);        // 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;    }    /**     * Creates and returns a sample thermometer chart.     *     * @return a sample thermometer chart.     */    public JFreeChart createThermometerChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("meter.thermo.title");        final String subtitleStr = this.resources.getString("meter.thermo.subtitle");        final String units = this.resources.getString("meter.thermo.units");        final DefaultValueDataset data = new DefaultValueDataset(new Double(34.0));        final ThermometerPlot plot = new ThermometerPlot(data);        plot.setUnits(units);        final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 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;    }    /**     * Creates and returns a sample meter chart.     *     * @return a meter chart.     */    public JFreeChart createMeterChartCircle() {        // create a default chart based on some sample data...        final String title = this.resources.getString("meter.meter.title");        final String subtitleStr = this.resources.getString("meter.meter.subtitle");        //String units = resources.getString("meter.meter.units");        //DefaultMeterDataset data = DemoDatasetFactory.createMeterDataset();        final DefaultValueDataset data = new DefaultValueDataset(50.0);        //data.setUnits(units);        final MeterPlot plot = new MeterPlot(data);        plot.setMeterAngle(270);        plot.setDialShape(DialShape.CIRCLE);        final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,                                          plot, 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;    }    /**     * Creates and returns a sample meter chart.     *     * @return a meter chart.     */    public JFreeChart createMeterChartPie() {        // create a default chart based on some sample data...        final String title = this.resources.getString("meter.meter.title");        final String subtitleStr = this.resources.getString("meter.meter.subtitle");        //String units = resources.getString("meter.meter.units");        //DefaultMeterDataset data = DemoDatasetFactory.createMeterDataset();        final DefaultValueDataset data = new DefaultValueDataset(50.0);        //data.setUnits(units);        final MeterPlot plot = new MeterPlot(data);        plot.setMeterAngle(270);        plot.setDialShape(DialShape.PIE);        final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 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;    }    /**     * Creates and returns a sample meter chart.     *     * @return the meter chart.     */    public JFreeChart createMeterChartChord() {        // create a default chart based on some sample data...        final String title = this.resources.getString("meter.meter.title");        final String subtitleStr = this.resources.getString("meter.meter.subtitle");        //String units = resources.getString("meter.meter.units");        //DefaultMeterDataset data = DemoDatasetFactory.createMeterDataset();        final DefaultValueDataset data = new DefaultValueDataset(45.0);        //data.setUnits(units);        final MeterPlot plot = new MeterPlot(data);        plot.setMeterAngle(270);        plot.setDialShape(DialShape.CHORD);        final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 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;    }    /**     * Creates a compass chart.     *     * @return a compass chart.     */    public JFreeChart createCompassChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("meter.compass.title");        final String subtitleStr = this.resources.getString("meter.compass.subtitle");        final DefaultValueDataset data = new DefaultValueDataset(new Double(45.0));        final Plot plot = new CompassPlot(data);        final JFreeChart chart = new JFreeChart(            title,            JFreeChart.DEFAULT_TITLE_FONT,            plot,            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;    }    /**     * Creates and returns a sample wind plot.     *     * @return a sample wind plot.     */    public JFreeChart createWindPlot() {        // create a default chart based on some sample data...        final String title = this.resources.getString("other.wind.title");        final String domain = this.resources.getString("other.wind.domain");        final String range = this.resources.getString("other.wind.range");        final WindDataset data = DemoDatasetFactory.createWindDataset1();        final JFreeChart chart = ChartFactory.createWindPlot(title, domain, range, data,                                                       true,                                                       false,                                                       false);        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));        return chart;    }    /**     * Creates and returns a sample scatter plot.     *     * @return a sample scatter plot.     */    public JFreeChart createScatterPlot() {        // create a default chart based on some sample data...        final String title = this.resources.getString("other.scatter.title");        final String domain = this.resources.getString("other.scatter.domain");        final String range = this.resources.getString("other.scatter.range");        final XYDataset data = new SampleXYDataset2();        final JFreeChart chart = ChartFactory.createScatterPlot(            title,            domain,            range,            data,            PlotOrientation.VERTICAL,            true,            true,  // tooltips            false  // urls        );        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));        final XYPlot plot = chart.getXYPlot();        plot.setDomainCrosshairVisible(true);        plot.setRangeCrosshairVisible(true);        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();        rangeAxis.setAutoRangeIncludesZero(false);        return chart;    }    /**     * Creates and returns a sample line chart.     *     * @return a line chart.     */    public JFreeChart createLineChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("other.line.title");        final String domain = this.resources.getString("other.line.domain");        final String range = this.resources.getString("other.line.range");        final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();        final JFreeChart chart = ChartFactory.createLineChart(title, domain, range, data,                                                        PlotOrientation.VERTICAL,                                                        true,                                                        true,                                                        false);        // then customise it a little...        chart.setBackgroundImage(JFreeChart.INFO.getLogo());        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));        final CategoryPlot plot = (CategoryPlot) chart.getPlot();        plot.setBackgroundAlpha(0.65f);        return chart;    }    /**     * Creates and returns a sample vertical XY bar chart.     *     * @return a sample vertical XY bar chart.     */    public JFreeChart createVerticalXYBarChart() {        // create a default chart based on some sample data...        final String title = this.resources.getString("other.xybar.title");        final String domain = this.resources.getString("other.xybar.domain");        final String range = this.resources.getString("other.xybar.range");        final TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1();        data.setDomainIsPointsInTime(false);        final JFreeChart chart = ChartFactory.createXYBarChart(            title,            domain,            true,            range,            data,            PlotOrientation.VERTICAL,            true,            false,            false        );        // then customise it a little...        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));        final XYItemRenderer renderer = chart.getXYPlot().getRenderer();        renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());        return chart;    }    /**     * Creates and returns a sample XY chart with null data.

⌨️ 快捷键说明

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