本文整理汇总了Java中org.jfree.chart.JFreeChart.getLegend方法的典型用法代码示例。如果您正苦于以下问题:Java JFreeChart.getLegend方法的具体用法?Java JFreeChart.getLegend怎么用?Java JFreeChart.getLegend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jfree.chart.JFreeChart
的用法示例。
在下文中一共展示了JFreeChart.getLegend方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: legendPositionChanged
import org.jfree.chart.JFreeChart; //导入方法依赖的package包/类
private void legendPositionChanged(LegendPosition legendPosition) {
JFreeChart chart = getCurrentChart();
if (chart != null) {
LegendTitle legend = chart.getLegend();
RectangleEdge position = legendPosition.getPosition();
if (legend != null) {
if (position != null) {
legend.setPosition(position);
} else {
while (chart.getLegend() != null) {
chart.removeLegend();
}
}
} else {
if (position != null) {
resetLegend();
}
}
}
}
示例2: paintDeviationChart
import org.jfree.chart.JFreeChart; //导入方法依赖的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);
}
示例3: setLegendProperties
import org.jfree.chart.JFreeChart; //导入方法依赖的package包/类
/**
* Sets the properties of the specified legend to match the properties
* defined on this panel.
*
* @param chart the chart whose legend is to be modified.
*/
public void setLegendProperties(JFreeChart chart) {
if(this.showLegend) {
Legend legend = chart.getLegend();
if(legend == null) {
legend = new StandardLegend();
chart.setLegend(legend);
}
if (legend instanceof StandardLegend) {
// only supports StandardLegend at present
StandardLegend standard = (StandardLegend) legend;
standard.setOutlineStroke(getOutlineStroke());
standard.setOutlinePaint(getOutlinePaint());
standard.setBackgroundPaint(getBackgroundPaint());
standard.setItemFont(getSeriesFont());
standard.setItemPaint(getSeriesPaint());
}
else {
// raise exception - unrecognised legend
}
}
else {
chart.setLegend(null);
}
}
示例4: updatePlotter
import org.jfree.chart.JFreeChart; //导入方法依赖的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);
}
示例5: createChart
import org.jfree.chart.JFreeChart; //导入方法依赖的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;
}
示例6: createChart
import org.jfree.chart.JFreeChart; //导入方法依赖的package包/类
public static JFreeChart createChart(XYDataset xydataset, String shou, String shu) {
JFreeChart jfreechart = ChartFactory.createScatterPlot("Rating and Rating People Distribution", shou, shu,
xydataset, PlotOrientation.VERTICAL, true, false, false);
jfreechart.setBackgroundPaint(Color.white);
jfreechart.setBorderPaint(Color.GREEN);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setNoDataMessage("no data");
xyplot.setNoDataMessageFont(new Font("微软雅黑", Font.BOLD, 14));
xyplot.setNoDataMessagePaint(Color.blue);
xyplot.setBackgroundPaint(Color.lightGray);
TextTitle textTitle = jfreechart.getTitle();
textTitle.setFont(new Font("宋体", Font.BOLD, 20));
LegendTitle legend = jfreechart.getLegend();
if (legend != null) {
legend.setItemFont(new Font("宋体", Font.BOLD, 20));
}
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setSeriesOutlinePaint(0, Color.WHITE);
renderer.setUseOutlinePaint(true);
renderer.setSeriesOutlineStroke(1, new BasicStroke(0.5F));
xyplot.setRenderer(renderer);
NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
numberaxis.setTickMarkInsideLength(3.0F);
numberaxis.setTickMarkOutsideLength(0.0F);
numberaxis.setUpperBound(280000);
numberaxis.setLowerBound(50000);
numberaxis.setAxisLineStroke(new BasicStroke(1.5f));
NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
numberaxis1.setUpperBound(10.0);
numberaxis1.setLowerBound(5.0);
NumberTickUnit ntu1 = new NumberTickUnit(0.5);
numberaxis1.setTickUnit(ntu1);
return jfreechart;
}
示例7: GraphGenerator
import org.jfree.chart.JFreeChart; //导入方法依赖的package包/类
public GraphGenerator(final String title, AthenaFeatures athenaFeatures, String feature) {
super(title);
this.feature = feature;
final XYDataset dataset = createDatasetFromFeatureData(athenaFeatures, feature);
final JFreeChart chart = createChart(dataset);
chart.setTitle("");
LegendTitle legend = (LegendTitle) chart.getLegend();
chart.removeLegend();
Font nwfont = new Font("Arial",1,12);
legend.setItemFont(nwfont);
legend.setPosition(RectangleEdge.TOP);
// legend.setWidth(200);
legend.setItemLabelPadding(new RectangleInsets(3, 3, 3, 3));
legend.setHeight(10);
// legend.setPadding(new RectangleInsets(10, 10, 10, 10));
XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.98, legend, RectangleAnchor.TOP_RIGHT);
ta.setMaxWidth(0.95);
// chart.addLegend(legend);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainZeroBaselinePaint(Color.gray);
plot.setDomainGridlinePaint(Color.gray);
plot.setDomainGridlineStroke(new BasicStroke(0.7f));
plot.setRangeGridlinePaint(Color.gray);
plot.setRangeGridlineStroke(new BasicStroke(0.7f));
plot.setDomainMinorGridlinePaint(Color.black);
plot.addAnnotation(ta);
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesPaint(0, Color.black);
renderer.setSeriesShape(0, ShapeUtilities.createDiamond(5));
renderer.setSeriesPaint(1, Color.red);
renderer.setSeriesShape(1, ShapeUtilities.createUpTriangle(5));
renderer.setSeriesPaint(2, Color.blue);
Shape shape = new Ellipse2D.Double(-5.0,-5.0,10,10);
renderer.setSeriesShape(2, shape);
renderer.setShapesFilled(false);
// renderer.setSeriesShapesVisible(1, false);
//apply theme
// StandardChartTheme.createJFreeTheme().apply(chart);
plot.setRenderer(renderer);
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setLabel(feature + " (K)");
yAxis.setAxisLineVisible(false);
yAxis.setTickUnit(new NumberTickUnit(50000));
yAxis.setNumberFormatOverride(new ByteFormat());
yAxis.setRange(new Range(0, 160000));
plot.getRenderer().setBaseItemLabelsVisible(true);
DateAxis xAxis = (DateAxis) plot.getDomainAxis();
xAxis.setAxisLineVisible(false);
xAxis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss"));
xAxis.setTickUnit(new DateTickUnit(DateTickUnit.MINUTE, 3));
xAxis.setLabelFont(new Font("Arial",1,12));
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(631, 381));
chartPanel.setMouseZoomable(true, true);
setContentPane(chartPanel);
try {
ChartUtilities.saveChartAsPNG(new File("result.png"), chart, 631, 381);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}