chartfactory.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,514 行 · 第 1/5 页
JAVA
1,514 行
ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT ); renderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER ); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition( ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER ); renderer.setNegativeItemLabelPosition(position2); } if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); } if (urls) { renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator() ); } CategoryPlot plot = new CategoryPlot( dataset, categoryAxis, valueAxis, renderer ); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend ); return chart; } /** * Creates a stacked bar chart with default settings. The chart object * returned by this method uses a {@link CategoryPlot} instance as the * plot, with a {@link CategoryAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} * as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param domainAxisLabel the label for the category axis * (<code>null</code> permitted). * @param rangeAxisLabel the label for the value axis * (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation of the chart (horizontal or * vertical) (<code>null</code> not permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A stacked bar chart. */ public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); } if (urls) { renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator() ); } CategoryPlot plot = new CategoryPlot( dataset, categoryAxis, valueAxis, renderer ); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend ); return chart; } /** * Creates a bar chart with a 3D effect. The chart object returned by this * method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as * the range axis, and a {@link BarRenderer3D} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> not permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bar chart with a 3D effect. */ public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); BarRenderer3D renderer = new BarRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); } if (urls) { renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator() ); } CategoryPlot plot = new CategoryPlot( dataset, categoryAxis, valueAxis, renderer ); plot.setOrientation(orientation); if (orientation == PlotOrientation.HORIZONTAL) { // change rendering order to ensure that bar overlapping is the // right way around plot.setRowRenderingOrder(SortOrder.DESCENDING); plot.setColumnRenderingOrder(SortOrder.DESCENDING); } plot.setForegroundAlpha(0.75f); JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend ); return chart; } /** * Creates a stacked bar chart with a 3D effect and default settings. The * chart object returned by this method uses a {@link CategoryPlot} * instance as the plot, with a {@link CategoryAxis3D} for the domain axis, * a {@link NumberAxis3D} as the range axis, and a * {@link StackedBarRenderer3D} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> not permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A stacked bar chart with a 3D effect. */ public static JFreeChart createStackedBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); // create the renderer... CategoryItemRenderer renderer = new StackedBarRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); } if (urls) { renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator() ); } // create the plot... CategoryPlot plot = new CategoryPlot( dataset, categoryAxis, valueAxis, renderer ); plot.setOrientation(orientation); if (orientation == PlotOrientation.HORIZONTAL) { // change rendering order to ensure that bar overlapping is the // right way around plot.setColumnRenderingOrder(SortOrder.DESCENDING); } // create the chart... JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend ); return chart; } /** * Creates an area chart with default settings. The chart object returned * by this method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and an {@link AreaRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (<code>null</code> not * permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return An area chart. */ public static JFreeChart createAreaChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); AreaRenderer renderer = new AreaRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator() ); } if (urls) { renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator() ); } CategoryPlot plot = new CategoryPlot( dataset, categoryAxis, valueAxis, renderer ); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend ); return chart; } /** * Creates a stacked area chart with default settings. The chart object * returned by this method uses a {@link CategoryPlot} instance as the * plot, with a {@link CategoryAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer} * as the renderer. * * @param title the chart title (<code>null</code> permitted).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?