📄 chartfactory.java
字号:
* @param yAxisLabel a label for the Y-axis.
* @param dataset the dataset for the chart.
* @param orientation the plot orientation (horizontal or vertical).
* @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 The chart.
*/
public static JFreeChart createXYLineChart(String title,
String xAxisLabel,
String yAxisLabel,
XYDataset dataset,
PlotOrientation orientation,
boolean legend,
boolean tooltips,
boolean urls) {
NumberAxis xAxis = new NumberAxis(xAxisLabel);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES);
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
plot.setOrientation(orientation);
if (tooltips) {
renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
}
if (urls) {
renderer.setURLGenerator(new StandardXYURLGenerator());
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates an area chart using an {@link XYDataset}.
*
* @param title the chart title.
* @param xAxisLabel a label for the X-axis.
* @param yAxisLabel a label for the Y-axis.
* @param data the dataset for the chart.
* @param orientation the plot orientation (horizontal or vertical).
* @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 XY area chart.
*
* @deprecated Use createXYAreaChart(...).
*/
public static JFreeChart createAreaXYChart(String title,
String xAxisLabel,
String yAxisLabel,
XYDataset data,
PlotOrientation orientation,
boolean legend,
boolean tooltips,
boolean urls) {
return createXYAreaChart(
title, xAxisLabel, yAxisLabel, data, orientation, legend, tooltips, urls
);
}
/**
* Creates an area chart using an {@link XYDataset}.
*
* @param title the chart title.
* @param xAxisLabel a label for the X-axis.
* @param yAxisLabel a label for the Y-axis.
* @param data the dataset for the chart.
* @param orientation the plot orientation (horizontal or vertical).
* @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 XY area chart.
*/
public static JFreeChart createXYAreaChart(String title,
String xAxisLabel,
String yAxisLabel,
XYDataset data,
PlotOrientation orientation,
boolean legend,
boolean tooltips,
boolean urls) {
NumberAxis xAxis = new NumberAxis(xAxisLabel);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
plot.setOrientation(orientation);
XYToolTipGenerator toolTipGenerator = null;
if (tooltips) {
toolTipGenerator = new StandardXYToolTipGenerator();
}
XYURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYURLGenerator();
}
plot.setRenderer(new AreaXYRenderer(AreaXYRenderer.AREA, toolTipGenerator, urlGenerator));
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates a scatter plot with default settings.
*
* @param title the chart title.
* @param xAxisLabel a label for the X-axis.
* @param yAxisLabel a label for the Y-axis.
* @param data the dataset for the chart.
* @param orientation the plot orientation (horizontal or vertical).
* @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 scatter plot.
*/
public static JFreeChart createScatterPlot(String title,
String xAxisLabel,
String yAxisLabel,
XYDataset data,
PlotOrientation orientation,
boolean legend,
boolean tooltips,
boolean urls) {
NumberAxis xAxis = new NumberAxis(xAxisLabel);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
yAxis.setAutoRangeIncludesZero(false);
XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
XYToolTipGenerator toolTipGenerator = null;
if (tooltips) {
toolTipGenerator = new StandardXYToolTipGenerator();
}
XYURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYURLGenerator();
}
StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES,
toolTipGenerator,
urlGenerator);
renderer.setShapesFilled(Boolean.TRUE);
plot.setRenderer(renderer);
plot.setOrientation(orientation);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates a bubble chart with default settings.
*
* @param title the chart title.
* @param xAxisLabel a label for the X-axis.
* @param yAxisLabel a label for the Y-axis.
* @param data the dataset for the chart.
* @param orientation the orientation (horizontal or vertical).
* @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 scatter plot.
*/
public static JFreeChart createBubbleChart(String title,
String xAxisLabel,
String yAxisLabel,
XYZDataset data,
PlotOrientation orientation,
boolean legend,
boolean tooltips,
boolean urls) {
NumberAxis xAxis = new NumberAxis(xAxisLabel);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
yAxis.setAutoRangeIncludesZero(false);
XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
XYZToolTipGenerator toolTipGenerator = null;
if (tooltips) {
toolTipGenerator = new StandardXYZToolTipGenerator();
}
XYZURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYZURLGenerator();
}
XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
renderer.setToolTipGenerator(toolTipGenerator);
renderer.setURLGenerator(urlGenerator);
plot.setRenderer(renderer);
plot.setOrientation(orientation);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates a wind plot with default settings.
*
* @param title the chart title.
* @param xAxisLabel a label for the x-axis.
* @param yAxisLabel a label for the y-axis.
* @param data the dataset for the chart.
* @param legend a flag that controls whether or not a legend is created.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
*
* @return a wind plot.
*
*/
public static JFreeChart createWindPlot(String title,
String xAxisLabel,
String yAxisLabel,
WindDataset data,
boolean legend,
boolean tooltips,
boolean urls) {
ValueAxis xAxis = new DateAxis(xAxisLabel);
ValueAxis yAxis = new NumberAxis(yAxisLabel);
yAxis.setMaximumAxisValue(12.0);
yAxis.setMinimumAxisValue(-12.0);
XYToolTipGenerator tooltipGenerator = null;
if (tooltips) {
tooltipGenerator = new StandardXYToolTipGenerator();
}
XYURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYURLGenerator();
}
XYPlot plot = new XYPlot(data, xAxis, yAxis, null);
WindItemRenderer renderer = new WindItemRenderer();
renderer.setToolTipGenerator(tooltipGenerator);
renderer.setURLGenerator(urlGenerator);
plot.setRenderer(renderer);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates and returns a time series chart.
* <P>
* A time series chart is an XYPlot with a date axis (horizontal) and a number axis (vertical),
* and each data item is connected with a line.
* <P>
* Note that you can supply a TimeSeriesCollection to this method, as it implements the
* XYDataset interface.
*
* @param title the chart title.
* @param timeAxisLabel a label for the time axis.
* @param valueAxisLabel a label for the value axis.
* @param data the dataset for the chart.
* @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 time series chart.
*/
public static JFreeChart createTimeSeriesChart(String title,
String timeAxisLabel,
String valueAxisLabel,
XYDataset data,
boolean legend,
boolean tooltips,
boolean urls) {
ValueAxis timeAxis = new DateAxis(timeAxisLabel);
timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
timeAxis.setUpperMargin(0.02);
NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
valueAxis.setAutoRangeIncludesZero(false); // override default
XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);
XYToolTipGenerator tooltipGenerator = null;
if (tooltips) {
tooltipGenerator = new TimeSeriesToolTipGenerator();
}
XYURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYURLGenerator();
}
plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES,
tooltipGenerator, urlGenerator));
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
/**
* Creates and returns a default instance of an XY bar chart.
*
* @param title the chart title.
* @param xAxisLabel a label for the X-axis.
* @param yAxisLabel a label for the Y-axis.
* @param data the dataset for the chart.
* @param orientation the orientation (horizontal or vertical).
* @param legend a flag specifying whether or not a legend is required.
* @param tooltips configure chart to generate tool tips?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -