本文整理汇总了Java中org.jfree.chart.title.LegendTitle.setFrame方法的典型用法代码示例。如果您正苦于以下问题:Java LegendTitle.setFrame方法的具体用法?Java LegendTitle.setFrame怎么用?Java LegendTitle.setFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jfree.chart.title.LegendTitle
的用法示例。
在下文中一共展示了LegendTitle.setFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintDeviationChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
public void paintDeviationChart(Graphics graphics, int width, int height) {
prepareData();
JFreeChart chart = createChart(this.dataset);
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// legend settings
LegendTitle legend = chart.getLegend();
if (legend != null) {
legend.setPosition(RectangleEdge.TOP);
legend.setFrame(BlockBorder.NONE);
legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
}
Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height);
chart.draw((Graphics2D) graphics, drawRect);
}
示例2: setLegend
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
private void setLegend(JFreeChart chart) {
chart.removeLegend();
final LegendTitle legend = new LegendTitle(new SpectrumLegendItemSource());
legend.setPosition(RectangleEdge.BOTTOM);
LineBorder border = new LineBorder(Color.BLACK, new BasicStroke(), new RectangleInsets(2, 2, 2, 2));
legend.setFrame(border);
chart.addLegend(legend);
}
示例3: createLegendTitles
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
/**
* Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
* Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
* {@link DimensionConfig} s.
*/
private List<LegendTitle> createLegendTitles() {
List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration();
LegendTitle legendTitle = new SmartLegendTitle(this, new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2), new ColumnArrangement(
HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2));
legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());
RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
if (position == null) {
return legendTitles;
}
legendTitle.setPosition(position);
if (legendConfiguration.isShowLegendFrame()) {
legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
}
ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
wrapper.add(legendTitle.getItemContainer());
wrapper.setPadding(3, 3, 3, 3);
legendTitle.setWrapper(wrapper);
legendTitles.add(legendTitle);
return legendTitles;
}
示例4: paintDeviationChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
public void paintDeviationChart(Graphics graphics, int width, int height) {
prepareData();
JFreeChart chart = createChart(this.dataset);
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// legend settings
LegendTitle legend = chart.getLegend();
if (legend != null) {
legend.setPosition(RectangleEdge.TOP);
legend.setFrame(BlockBorder.NONE);
legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
}
Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height);
chart.draw((Graphics2D)graphics, drawRect);
}
示例5: createLegendTitles
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
/**
* Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
* Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
* {@link DimensionConfig} s.
*/
private List<LegendTitle> createLegendTitles() {
List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration();
LegendTitle legendTitle = new SmartLegendTitle(this, new FlowArrangement(HorizontalAlignment.CENTER,
VerticalAlignment.CENTER, 30, 2), new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER,
0, 2));
legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());
RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
if (position == null) {
return legendTitles;
}
legendTitle.setPosition(position);
if (legendConfiguration.isShowLegendFrame()) {
legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
}
ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
wrapper.add(legendTitle.getItemContainer());
wrapper.setPadding(3, 3, 3, 3);
legendTitle.setWrapper(wrapper);
legendTitles.add(legendTitle);
return legendTitles;
}
示例6: createLegendTitles
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
/**
* Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
* Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
* {@link DimensionConfig} s.
*/
private List<LegendTitle> createLegendTitles() {
List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration();
LegendTitle legendTitle = new SmartLegendTitle(this,
new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2),
new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2));
legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());
RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
if (position == null) {
return legendTitles;
}
legendTitle.setPosition(position);
if (legendConfiguration.isShowLegendFrame()) {
legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
}
ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
wrapper.add(legendTitle.getItemContainer());
wrapper.setPadding(3, 3, 3, 3);
legendTitle.setWrapper(wrapper);
legendTitles.add(legendTitle);
return legendTitles;
}
示例7: setLegend
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
private void setLegend(JFreeChart chart, Plot plot, Font font) {
if(!showlegend) return;
Color bg = backgroundcolor==null?databackgroundcolor:backgroundcolor;
if(font==null)font=getFont();
LegendTitle legend = legendMultiLine?
new LegendTitle(plot,new ColumnArrangement(), new ColumnArrangement()):
new LegendTitle(plot);
legend.setBackgroundPaint(bg);
legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
legend.setFrame(new LineBorder());
legend.setPosition(RectangleEdge.BOTTOM);
legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
legend.setWidth(chartwidth-20);// geht nicht
legend.setItemFont(font);
legend.setItemPaint(foregroundcolor);
//RectangleInsets labelPadding;
legend.setItemLabelPadding(new RectangleInsets(2,2,2,2));
legend.setBorder(0,0,0,0);
legend.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
legend.setLegendItemGraphicPadding(new RectangleInsets(8,10,0,0));
chart.addLegend(legend);
}
示例8: updatePlotter
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
@Override
protected void updatePlotter() {
int categoryCount = prepareData();
String maxClassesProperty = ParameterService
.getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
int maxClasses = 20;
try {
if (maxClassesProperty != null) {
maxClasses = Integer.parseInt(maxClassesProperty);
}
} catch (NumberFormatException e) {
// LogService.getGlobal().log("Series plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
// LogService.WARNING);
LogService.getRoot().log(Level.WARNING,
"com.rapidminer.gui.plotter.charts.SeriesChartPlotter.parsing_property_error");
}
boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;
JFreeChart chart = createChart(this.dataset, createLegend);
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// domain axis
if (axis[INDEX] >= 0) {
if (!dataTable.isNominal(axis[INDEX])) {
if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) {
DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX]));
domainAxis.setTimeZone(Tools.getPreferredTimeZone());
chart.getXYPlot().setDomainAxis(domainAxis);
if (getRangeForDimension(axis[INDEX]) != null) {
domainAxis.setRange(getRangeForDimension(axis[INDEX]));
}
domainAxis.setLabelFont(LABEL_FONT_BOLD);
domainAxis.setTickLabelFont(LABEL_FONT);
domainAxis.setVerticalTickLabels(isLabelRotating());
}
} else {
LinkedHashSet<String> values = new LinkedHashSet<String>();
for (DataTableRow row : dataTable) {
String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX]));
if (stringValue.length() > 40) {
stringValue = stringValue.substring(0, 40);
}
values.add(stringValue);
}
ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]),
values.toArray(new String[values.size()]));
categoryAxis.setLabelFont(LABEL_FONT_BOLD);
categoryAxis.setTickLabelFont(LABEL_FONT);
categoryAxis.setVerticalTickLabels(isLabelRotating());
chart.getXYPlot().setDomainAxis(categoryAxis);
}
}
// legend settings
LegendTitle legend = chart.getLegend();
if (legend != null) {
legend.setPosition(RectangleEdge.TOP);
legend.setFrame(BlockBorder.NONE);
legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
legend.setItemFont(LABEL_FONT);
}
AbstractChartPanel panel = getPlotterPanel();
if (panel == null) {
panel = createPanel(chart);
} else {
panel.setChart(chart);
}
// ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
panel.getChartRenderingInfo().setEntityCollection(null);
}
示例9: createChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
private JFreeChart createChart(XYDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
null, // x axis label
null, // y axis label
dataset, // data
PlotOrientation.VERTICAL, true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
// get a reference to the plot for further customisation...
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
ValueAxis valueAxis = plot.getRangeAxis();
valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);
ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);
DeviationRenderer renderer = new DeviationRenderer(true, false);
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
if (dataset.getSeriesCount() == 1) {
renderer.setSeriesStroke(0, stroke);
renderer.setSeriesPaint(0, Color.RED);
renderer.setSeriesFillPaint(0, Color.RED);
} else if (dataset.getSeriesCount() == 2) {
renderer.setSeriesStroke(0, stroke);
renderer.setSeriesPaint(0, Color.RED);
renderer.setSeriesFillPaint(0, Color.RED);
renderer.setSeriesStroke(1, stroke);
renderer.setSeriesPaint(1, Color.BLUE);
renderer.setSeriesFillPaint(1, Color.BLUE);
} else {
for (int i = 0; i < dataset.getSeriesCount(); i++) {
renderer.setSeriesStroke(i, stroke);
Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
renderer.setSeriesPaint(i, color);
renderer.setSeriesFillPaint(i, color);
}
}
renderer.setAlpha(0.12f);
plot.setRenderer(renderer);
// legend settings
LegendTitle legend = chart.getLegend();
if (legend != null) {
legend.setPosition(RectangleEdge.TOP);
legend.setFrame(BlockBorder.NONE);
legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
legend.setItemFont(PlotterAdapter.LABEL_FONT);
}
return chart;
}
示例10: JFreeChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
/**
* Creates a new chart with the given title and plot. The
* <code>createLegend</code> argument specifies whether or not a legend
* should be added to the chart.
* <br><br>
* Note that the {@link ChartFactory} class contains a range
* of static methods that will return ready-made charts, and often this
* is a more convenient way to create charts than using this constructor.
*
* @param title the chart title (<code>null</code> permitted).
* @param titleFont the font for displaying the chart title
* (<code>null</code> permitted).
* @param plot controller of the visual representation of the data
* (<code>null</code> not permitted).
* @param createLegend a flag indicating whether or not a legend should
* be created for the chart.
*/
public JFreeChart(String title, Font titleFont, Plot plot,
boolean createLegend) {
if (plot == null) {
throw new NullPointerException("Null 'plot' argument.");
}
// create storage for listeners...
this.progressListeners = new EventListenerList();
this.changeListeners = new EventListenerList();
this.notify = true; // default is to notify listeners when the
// chart changes
this.renderingHints = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
this.borderVisible = false;
this.borderStroke = new BasicStroke(1.0f);
this.borderPaint = Color.black;
this.padding = RectangleInsets.ZERO_INSETS;
this.plot = plot;
plot.addChangeListener(this);
this.subtitles = new ArrayList();
// create a legend, if requested...
if (createLegend) {
LegendTitle legend = new LegendTitle(this.plot);
legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
legend.setFrame(new LineBorder());
legend.setBackgroundPaint(Color.white);
legend.setPosition(RectangleEdge.BOTTOM);
this.subtitles.add(legend);
}
// add the chart title, if one has been specified...
if (title != null) {
if (titleFont == null) {
titleFont = DEFAULT_TITLE_FONT;
}
this.title = new TextTitle(title, titleFont);
this.title.addChangeListener(this);
}
this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;
this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;
}
示例11: JFreeChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
/**
* Creates a new chart with the given title and plot. The
* <code>createLegend</code> argument specifies whether or not a legend
* should be added to the chart.
* <br><br>
* Note that the {@link ChartFactory} class contains a range
* of static methods that will return ready-made charts, and often this
* is a more convenient way to create charts than using this constructor.
*
* @param title the chart title (<code>null</code> permitted).
* @param titleFont the font for displaying the chart title
* (<code>null</code> permitted).
* @param plot controller of the visual representation of the data
* (<code>null</code> not permitted).
* @param createLegend a flag indicating whether or not a legend should
* be created for the chart.
*/
public JFreeChart(String title, Font titleFont, Plot plot,
boolean createLegend) {
ParamChecks.nullNotPermitted(plot, "plot");
// create storage for listeners...
this.progressListeners = new EventListenerList();
this.changeListeners = new EventListenerList();
this.notify = true; // default is to notify listeners when the
// chart changes
this.renderingHints = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// added the following hint because of
// http://stackoverflow.com/questions/7785082/
this.renderingHints.put(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_PURE);
this.borderVisible = false;
this.borderStroke = new BasicStroke(1.0f);
this.borderPaint = Color.black;
this.padding = RectangleInsets.ZERO_INSETS;
this.plot = plot;
plot.addChangeListener(this);
this.subtitles = new ArrayList();
// create a legend, if requested...
if (createLegend) {
LegendTitle legend = new LegendTitle(this.plot);
legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
legend.setFrame(new LineBorder());
legend.setBackgroundPaint(Color.white);
legend.setPosition(RectangleEdge.BOTTOM);
this.subtitles.add(legend);
legend.addChangeListener(this);
}
// add the chart title, if one has been specified...
if (title != null) {
if (titleFont == null) {
titleFont = DEFAULT_TITLE_FONT;
}
this.title = new TextTitle(title, titleFont);
this.title.addChangeListener(this);
}
this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;
this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;
}
示例12: setChartLegend
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
protected void setChartLegend(JFreeChart jfreeChart, Integer baseFontSize)
{
//The legend visibility is already taken into account in the jfreeChart object's constructor
LegendTitle legend = jfreeChart.getLegend();
if (legend != null)
{
Font themeLegendFont = getFont((JRFont)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FONT), getChart().getLegendFont(), baseFontSize);
legend.setItemFont(themeLegendFont);
Color legendForecolor = getChart().getOwnLegendColor() != null ?
getChart().getOwnLegendColor() :
(getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) != null ?
(Color)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) :
getChart().getLegendColor());
if (legendForecolor != null)
legend.setItemPaint(legendForecolor);
Color legendBackcolor = getChart().getOwnLegendBackgroundColor() != null ?
getChart().getOwnLegendBackgroundColor() :
(getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) != null ?
(Color)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) :
getChart().getLegendBackgroundColor());
if (legendBackcolor != null)
legend.setBackgroundPaint(legendBackcolor);
BlockFrame frame = (BlockFrame)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FRAME);
if (frame != null)
legend.setFrame(frame);
HorizontalAlignment defaultLegendHAlignment = (HorizontalAlignment)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_HORIZONTAL_ALIGNMENT);
if (defaultLegendHAlignment != null)
legend.setHorizontalAlignment(defaultLegendHAlignment);
VerticalAlignment defaultLegendVAlignment = (VerticalAlignment)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_VERTICAL_ALIGNMENT);
if (defaultLegendVAlignment != null)
legend.setVerticalAlignment(defaultLegendVAlignment);
RectangleInsets defaultLegendPadding = (RectangleInsets)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_PADDING);
RectangleInsets legendPadding = legend.getPadding() != null ? legend.getPadding() : defaultLegendPadding;
if (legendPadding != null)
legend.setPadding(legendPadding);
RectangleEdge defaultLegendPosition = (RectangleEdge)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_POSITION);
if (getEdge(getChart().getLegendPositionValue(), defaultLegendPosition) != null)
legend.setPosition(getEdge(getChart().getLegendPositionValue(), defaultLegendPosition));
}
}
示例13: doGet
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
String action = WebUtils.getString(request, "action", "graph");
String type = WebUtils.getString(request, "t");
JFreeChart chart = null;
updateSessionManager(request);
try {
if ("refresh".equals(action)) {
new RepositoryInfo().runAs(null);
ServletContext sc = getServletContext();
sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
} else {
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
chart = repoStats(type);
} else if (DISK.equals(type)) {
chart = diskStats();
} else if (JVM_MEMORY.equals(type)) {
chart = jvmMemStats();
} else if (OS_MEMORY.equals(type)) {
chart = osMemStats();
}
if (chart != null) {
// Customize title font
chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));
// Match body { background-color:#F6F6EE; }
chart.setBackgroundPaint(new Color(246, 246, 238));
// Customize no data
PiePlot plot = (PiePlot) chart.getPlot();
plot.setNoDataMessage("No data to display");
// Customize labels
plot.setLabelGenerator(null);
// Customize legend
LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
legend.setPosition(RectangleEdge.BOTTOM);
legend.setFrame(BlockBorder.NONE);
legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
chart.removeLegend();
chart.addLegend(legend);
if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
} else {
ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
}
}
out.flush();
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: HistogramChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
public HistogramChart() {
super(null, true);
// initialize the chart by default time series chart from factory
chart = ChartFactory.createHistogram("", // title
"", // x-axis label
"", // y-axis label
null, // data set
PlotOrientation.VERTICAL, // orientation
true, // create legend
false, // generate tooltips
false // generate URLs
);
// title
chartTitle = chart.getTitle();
chartTitle.setFont(titleFont);
chartTitle.setMargin(5, 0, 0, 0);
chartSubTitle = new TextTitle();
chartSubTitle.setFont(subTitleFont);
chartSubTitle.setMargin(5, 0, 0, 0);
chart.addSubtitle(chartSubTitle);
// legend constructed by ChartFactory
LegendTitle legend = chart.getLegend();
legend.setItemFont(legendFont);
legend.setFrame(BlockBorder.NONE);
chart.setBackgroundPaint(Color.white);
setChart(chart);
// disable maximum size (we don't want scaling)
setMaximumDrawWidth(Integer.MAX_VALUE);
setMaximumDrawHeight(Integer.MAX_VALUE);
// set the plot properties
plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
// set grid properties
plot.setDomainGridlinePaint(gridColor);
plot.setRangeGridlinePaint(gridColor);
// set crosshair (selection) properties
plot.setDomainCrosshairVisible(false);
plot.setRangeCrosshairVisible(true);
// set the logarithmic axis
NumberAxis axisDomain = new HistogramDomainAxis();
axisDomain.setMinorTickCount(1);
axisDomain.setAutoRange(true);
NumberAxis axisRange = new NumberAxis();
axisRange.setMinorTickCount(1);
axisRange.setAutoRange(true);
plot.setDomainAxis(axisDomain);
plot.setRangeAxis(axisRange);
ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
renderer.setMargin(marginSize);
renderer.setShadowVisible(false);
plot.setRenderer(renderer);
this.setMinimumSize(new Dimension(400, 400));
this.setDismissDelay(Integer.MAX_VALUE);
this.setInitialDelay(0);
}
示例15: JFreeChart
import org.jfree.chart.title.LegendTitle; //导入方法依赖的package包/类
/**
* Creates a new chart with the given title and plot. The
* <code>createLegend</code> argument specifies whether or not a legend
* should be added to the chart.
* <br><br>
* Note that the {@link ChartFactory} class contains a range
* of static methods that will return ready-made charts, and often this
* is a more convenient way to create charts than using this constructor.
*
* @param title the chart title (<code>null</code> permitted).
* @param titleFont the font for displaying the chart title
* (<code>null</code> permitted).
* @param plot controller of the visual representation of the data
* (<code>null</code> not permitted).
* @param createLegend a flag indicating whether or not a legend should
* be created for the chart.
*/
public JFreeChart(String title, Font titleFont, Plot plot,
boolean createLegend) {
if (plot == null) {
throw new NullPointerException("Null 'plot' argument.");
}
// create storage for listeners...
this.progressListeners = new EventListenerList();
this.changeListeners = new EventListenerList();
this.notify = true; // default is to notify listeners when the
// chart changes
this.renderingHints = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
this.borderVisible = false;
this.borderStroke = new BasicStroke(1.0f);
this.borderPaint = Color.black;
this.padding = RectangleInsets.ZERO_INSETS;
this.plot = plot;
plot.addChangeListener(this);
this.subtitles = new ArrayList();
// create a legend, if requested...
if (createLegend) {
LegendTitle legend = new LegendTitle(this.plot);
legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
legend.setFrame(new LineBorder());
legend.setBackgroundPaint(Color.white);
legend.setPosition(RectangleEdge.BOTTOM);
this.subtitles.add(legend);
legend.addChangeListener(this);
}
// add the chart title, if one has been specified...
if (title != null) {
if (titleFont == null) {
titleFont = DEFAULT_TITLE_FONT;
}
this.title = new TextTitle(title, titleFont);
this.title.addChangeListener(this);
}
this.backgroundPaint = DEFAULT_BACKGROUND_PAINT;
this.backgroundImage = DEFAULT_BACKGROUND_IMAGE;
this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT;
this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA;
}